blob: 4ced3c3ccae32a0af82b6e509d6eb348c17c6eb7 [file] [log] [blame]
Pavlin Radoslavov5cf1fe02014-07-03 22:52:25 -07001package net.onrc.onos.core.topology.web.serializers;
2
3import java.io.IOException;
4
5import net.onrc.onos.core.topology.DeviceEvent;
Yuta HIGUCHI1222ac52014-07-09 16:50:28 -07006import net.onrc.onos.core.topology.TopologyElement;
Pavlin Radoslavov5cf1fe02014-07-03 22:52:25 -07007import net.onrc.onos.core.util.SwitchPort;
8
9import org.codehaus.jackson.JsonGenerator;
10import org.codehaus.jackson.map.SerializerProvider;
11import org.codehaus.jackson.map.ser.std.SerializerBase;
12
13public class DeviceEventSerializer extends SerializerBase<DeviceEvent> {
14
15 public DeviceEventSerializer() {
16 super(DeviceEvent.class);
17 }
18
19 @Override
20 public void serialize(DeviceEvent deviceEvent, JsonGenerator jsonGenerator,
21 SerializerProvider serializerProvider) throws IOException {
22
23 //
24 // TODO: For now, the JSON format of the serialized output should
25 // be same as the JSON format of the corresponding class Device.
26 // In the future, we will use a single serializer.
27 //
28
29 jsonGenerator.writeStartObject();
Yuta HIGUCHI1222ac52014-07-09 16:50:28 -070030 jsonGenerator.writeStringField(TopologyElement.TYPE, deviceEvent.getType());
Pavlin Radoslavov5cf1fe02014-07-03 22:52:25 -070031 jsonGenerator.writeStringField("mac", deviceEvent.getMac().toString());
32 jsonGenerator.writeFieldName("attachmentPoints");
33 jsonGenerator.writeStartArray();
34 for (SwitchPort switchPort : deviceEvent.getAttachmentPoints()) {
35 jsonGenerator.writeObject(switchPort);
36 }
37 jsonGenerator.writeEndArray();
38 jsonGenerator.writeEndObject();
39 }
40}