Pavlin Radoslavov | 5cf1fe0 | 2014-07-03 22:52:25 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.topology.web.serializers; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | |
| 5 | import net.onrc.onos.core.topology.DeviceEvent; |
Yuta HIGUCHI | 1222ac5 | 2014-07-09 16:50:28 -0700 | [diff] [blame] | 6 | import net.onrc.onos.core.topology.TopologyElement; |
Pavlin Radoslavov | 5cf1fe0 | 2014-07-03 22:52:25 -0700 | [diff] [blame] | 7 | import net.onrc.onos.core.util.SwitchPort; |
| 8 | |
| 9 | import org.codehaus.jackson.JsonGenerator; |
| 10 | import org.codehaus.jackson.map.SerializerProvider; |
| 11 | import org.codehaus.jackson.map.ser.std.SerializerBase; |
| 12 | |
| 13 | public 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 HIGUCHI | 1222ac5 | 2014-07-09 16:50:28 -0700 | [diff] [blame] | 30 | jsonGenerator.writeStringField(TopologyElement.TYPE, deviceEvent.getType()); |
Pavlin Radoslavov | 5cf1fe0 | 2014-07-03 22:52:25 -0700 | [diff] [blame] | 31 | 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 | } |