TeruU | 65bc5ff | 2014-04-23 22:22:32 -0700 | [diff] [blame^] | 1 | package net.onrc.onos.core.topology.serializers; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | |
| 5 | import net.onrc.onos.core.topology.Device; |
| 6 | import net.onrc.onos.core.topology.Port; |
| 7 | import net.onrc.onos.core.topology.PortEvent.SwitchPort; |
| 8 | |
| 9 | import org.codehaus.jackson.JsonGenerationException; |
| 10 | import org.codehaus.jackson.JsonGenerator; |
| 11 | import org.codehaus.jackson.map.SerializerProvider; |
| 12 | import org.codehaus.jackson.map.ser.std.SerializerBase; |
| 13 | |
| 14 | public class DeviceSerializer extends SerializerBase<Device> { |
| 15 | |
| 16 | public DeviceSerializer() { |
| 17 | super(Device.class); |
| 18 | } |
| 19 | |
| 20 | @Override |
| 21 | public void serialize(Device dev, JsonGenerator jsonGenerator, |
| 22 | SerializerProvider serializerProvider) throws IOException, |
| 23 | JsonGenerationException { |
| 24 | jsonGenerator.writeStartObject(); |
| 25 | jsonGenerator.writeNumberField("mac", dev.getMacAddress().toLong()); |
| 26 | jsonGenerator.writeFieldName("attachmentPoints"); |
| 27 | jsonGenerator.writeStartArray(); |
| 28 | for (Port port : dev.getAttachmentPoints()) { |
| 29 | SwitchPort sp = new SwitchPort(port.getDpid(), port.getNumber()); |
| 30 | jsonGenerator.writeObject(sp); |
| 31 | } |
| 32 | jsonGenerator.writeEndArray(); |
| 33 | jsonGenerator.writeEndObject(); |
| 34 | } |
| 35 | |
| 36 | } |