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; |
| 6 | import net.onrc.onos.core.util.SwitchPort; |
| 7 | |
| 8 | import org.codehaus.jackson.JsonGenerator; |
| 9 | import org.codehaus.jackson.map.SerializerProvider; |
| 10 | import org.codehaus.jackson.map.ser.std.SerializerBase; |
| 11 | |
| 12 | public class DeviceEventSerializer extends SerializerBase<DeviceEvent> { |
| 13 | |
| 14 | public DeviceEventSerializer() { |
| 15 | super(DeviceEvent.class); |
| 16 | } |
| 17 | |
| 18 | @Override |
| 19 | public void serialize(DeviceEvent deviceEvent, JsonGenerator jsonGenerator, |
| 20 | SerializerProvider serializerProvider) throws IOException { |
| 21 | |
| 22 | // |
| 23 | // TODO: For now, the JSON format of the serialized output should |
| 24 | // be same as the JSON format of the corresponding class Device. |
| 25 | // In the future, we will use a single serializer. |
| 26 | // |
| 27 | |
| 28 | jsonGenerator.writeStartObject(); |
| 29 | jsonGenerator.writeStringField("mac", deviceEvent.getMac().toString()); |
| 30 | jsonGenerator.writeFieldName("attachmentPoints"); |
| 31 | jsonGenerator.writeStartArray(); |
| 32 | for (SwitchPort switchPort : deviceEvent.getAttachmentPoints()) { |
| 33 | jsonGenerator.writeObject(switchPort); |
| 34 | } |
| 35 | jsonGenerator.writeEndArray(); |
| 36 | jsonGenerator.writeEndObject(); |
| 37 | } |
| 38 | } |