public void writeNotificationRecords(OutputStream out, NotificationRecord[] value) throws IOException {
        writeStartArray(out);
        if (value == null) {
            writeEndArray(out);
            return;
        }

        for (NotificationRecord nr : value) {
            Notification item = nr.getNotification();
            writeArrayItem(out);
            writeStartObject(out);

            // Fields common to all notification classes
            Class<?> clazz = item.getClass();
            writeSimpleStringField(out, OM_CLASSNAME, clazz.getName());
            writeStringField(out, OM_TYPE, item.getType());
            ObjectName on = null;
            if (item.getSource() instanceof String) {
                try {
                    on = new ObjectName((String) item.getSource());
                } catch (Exception e) {
                }
            } else {
                on = (ObjectName) item.getSource();
            }

            writeObjectNameField(out, OM_SOURCE, on);
            writeLongField(out, OM_SEQUENCENUMBER, item.getSequenceNumber());
            writeLongField(out, OM_TIMESTAMP, item.getTimeStamp());
            writeStringField(out, OM_MESSAGE, item.getMessage());
            writePOJOField(out, OM_USERDATA, item.getUserData());

            // Write routing information (host name, server name, server user dir) if this is a routed notification.
            final Map<String, Object> routingInfo = nr.getNotificationTargetInformation().getRoutingInformation();
            if (routingInfo != null) {
                String hostName = (String) routingInfo.get(ClientProvider.ROUTING_KEY_HOST_NAME);
                String serverName = (String) routingInfo.get(ClientProvider.ROUTING_KEY_SERVER_NAME);
                String serverUserDir = (String) routingInfo.get(ClientProvider.ROUTING_KEY_SERVER_USER_DIR);

                writeStringField(out, OM_HOSTNAME, hostName);
                writeStringField(out, OM_SERVERNAME, serverName);
                writeStringField(out, OM_SERVERUSERDIR, serverUserDir);
            }

            if (clazz == Notification.class) {
            } else if (clazz == AttributeChangeNotification.class) {
                AttributeChangeNotification v = (AttributeChangeNotification) item;
                writeStringField(out, OM_ATTRIBUTENAME, v.getAttributeName());
                writeStringField(out, OM_ATTRIBUTETYPE, v.getAttributeType());
                writePOJOField(out, OM_OLDVALUE, v.getOldValue());
                writePOJOField(out, OM_NEWVALUE, v.getNewValue());
            } else if (clazz == JMXConnectionNotification.class) {
                JMXConnectionNotification v = (JMXConnectionNotification) item;
                writeStringField(out, OM_CONNECTIONID, v.getConnectionId());
            } else if (clazz == MBeanServerNotification.class) {
                MBeanServerNotification v = (MBeanServerNotification) item;
                writeObjectNameField(out, OM_MBEANNAME, v.getMBeanName());
            } else if (clazz == RelationNotification.class) {
                RelationNotification v = (RelationNotification) item;
                writeStringField(out, OM_RELATIONID, v.getRelationId());
                writeStringField(out, OM_RELATIONTYPENAME, v.getRelationTypeName());
                writeObjectNameField(out, OM_OBJECTNAME, v.getObjectName());
                String roleName = v.getRoleName();
                if (roleName == null) {
                    writeObjectNameListField(out, OM_MBEANSTOUNREGISTER, v.getMBeansToUnregister());
                } else {
                    writeStringField(out, OM_ROLENAME, v.getRoleName());
                    writeObjectNameListField(out, OM_OLDROLEVALUE, v.getOldRoleValue());
                    writeObjectNameListField(out, OM_NEWROLEVALUE, v.getNewRoleValue());
                }
            } else if (clazz == TimerNotification.class) {
                TimerNotification v = (TimerNotification) item;
                writeIntField(out, OM_NOTIFICATIONID, v.getNotificationID());
            } else {
                // MonitorNotification and TimerAlarmClockNotification are
                // known, but either the class or the constructor is not
                // visible, and we have to use base64.
                // SnmpTableEntryNotification is a sun specific implementation.
                writeSerializedField(out, OM_SERIALIZED, item);
            }

            writeEndObject(out);
        }
        writeEndArray(out);
    }
public void writeNotificationRecords ( OutputStream out , NotificationRecord [ ] value ) throws IOException { writeStartArray ( out ) ; if ( value == null ) { writeEndArray ( out ) ; return ; } for ( NotificationRecord nr : value ) { Notification item = nr . getNotification ( ) ; writeArrayItem ( out ) ; writeStartObject ( out ) ; Class < ? > clazz = item . getClass ( ) ; writeSimpleStringField ( out , OM_CLASSNAME , clazz . getName ( ) ) ; writeStringField ( out , OM_TYPE , item . getType ( ) ) ; ObjectName on = null ; if ( item . getSource ( ) instanceof String ) { try { on = new ObjectName ( ( String ) item . getSource ( ) ) ; } catch ( Exception e ) { } } else { on = ( ObjectName ) item . getSource ( ) ; } writeObjectNameField ( out , OM_SOURCE , on ) ; writeLongField ( out , OM_SEQUENCENUMBER , item . getSequenceNumber ( ) ) ; writeLongField ( out , OM_TIMESTAMP , item . getTimeStamp ( ) ) ; writeStringField ( out , OM_MESSAGE , item . getMessage ( ) ) ; writePOJOField ( out , OM_USERDATA , item . getUserData ( ) ) ; final Map < String , Object > routingInfo = nr . getNotificationTargetInformation ( ) . getRoutingInformation ( ) ; if ( routingInfo != null ) { String hostName = ( String ) routingInfo . get ( ClientProvider . ROUTING_KEY_HOST_NAME ) ; String serverName = ( String ) routingInfo . get ( ClientProvider . ROUTING_KEY_SERVER_NAME ) ; String serverUserDir = ( String ) routingInfo . get ( ClientProvider . ROUTING_KEY_SERVER_USER_DIR ) ; writeStringField ( out , OM_HOSTNAME , hostName ) ; writeStringField ( out , OM_SERVERNAME , serverName ) ; writeStringField ( out , OM_SERVERUSERDIR , serverUserDir ) ; } if ( clazz == Notification . class ) { } else if ( clazz == AttributeChangeNotification . class ) { AttributeChangeNotification v = ( AttributeChangeNotification ) item ; writeStringField ( out , OM_ATTRIBUTENAME , v . getAttributeName ( ) ) ; writeStringField ( out , OM_ATTRIBUTETYPE , v . getAttributeType ( ) ) ; writePOJOField ( out , OM_OLDVALUE , v . getOldValue ( ) ) ; writePOJOField ( out , OM_NEWVALUE , v . getNewValue ( ) ) ; } else if ( clazz == JMXConnectionNotification . class ) { JMXConnectionNotification v = ( JMXConnectionNotification ) item ; writeStringField ( out , OM_CONNECTIONID , v . getConnectionId ( ) ) ; } else if ( clazz == MBeanServerNotification . class ) { MBeanServerNotification v = ( MBeanServerNotification ) item ; writeObjectNameField ( out , OM_MBEANNAME , v . getMBeanName ( ) ) ; } else if ( clazz == RelationNotification . class ) { RelationNotification v = ( RelationNotification ) item ; writeStringField ( out , OM_RELATIONID , v . getRelationId ( ) ) ; writeStringField ( out , OM_RELATIONTYPENAME , v . getRelationTypeName ( ) ) ; writeObjectNameField ( out , OM_OBJECTNAME , v . getObjectName ( ) ) ; String roleName = v . getRoleName ( ) ; if ( roleName == null ) { writeObjectNameListField ( out , OM_MBEANSTOUNREGISTER , v . getMBeansToUnregister ( ) ) ; } else { writeStringField ( out , OM_ROLENAME , v . getRoleName ( ) ) ; writeObjectNameListField ( out , OM_OLDROLEVALUE , v . getOldRoleValue ( ) ) ; writeObjectNameListField ( out , OM_NEWROLEVALUE , v . getNewRoleValue ( ) ) ; } } else if ( clazz == TimerNotification . class ) { TimerNotification v = ( TimerNotification ) item ; writeIntField ( out , OM_NOTIFICATIONID , v . getNotificationID ( ) ) ; } else { writeSerializedField ( out , OM_SERIALIZED , item ) ; } writeEndObject ( out ) ; } writeEndArray ( out ) ; }
Encode an array of NotificationRecord instance as JSON:
[ {
"className" : "String", // The class name of the Notification object
"serialized" : "Base64", // If the object is not of one of the known
// classes, then base64 serialize it.
"type" : String,
"source" : POJO,
"sequenceNumber" : Long,
"timeStamp" : Long,
"message" : String,
"userData" : POJO,

"hostName" : String, // For routed Notifications only
"serverName" : String,
"serverUserDir" : String,

"attributeName" : String, // For AttributeChangeNotification only
"attributeType" : String,
"oldValue", POJO,
"newValue", POJO,

"connectionId" : String, // For JMXConnectionNotification

"mbeanName" : String, // For MBeanServerNotification

"relationId" : String, // For RelationNotification
"relationTypeName" : String,
"objectName" : String,
"mbeansToUnregister" : [ String* ],
"roleName" : String,
"oldRoleValue" : [String*],
"newRoleValue" : [String*],

"notificationID" : Integer, // For TimerNotification
} * ]

@param out The stream to write JSON to
@param value The NotificationRecord array to encode. Value can be null,
but its items can't be null.
The "source" of the items must be an instance of ObjectName.
@throws IOException If an I/O error occurs
@see #readNotificationRecords(InputStream)