Yuta HIGUCHI | a7f1cdd | 2014-06-09 15:05:20 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.topology.web.serializers; |
TeruU | 65bc5ff | 2014-04-23 22:22:32 -0700 | [diff] [blame] | 2 | |
| 3 | import java.io.IOException; |
| 4 | |
| 5 | import net.onrc.onos.core.topology.Device; |
| 6 | import net.onrc.onos.core.topology.Port; |
TeruU | 65bc5ff | 2014-04-23 22:22:32 -0700 | [diff] [blame] | 7 | |
TeruU | 65bc5ff | 2014-04-23 22:22:32 -0700 | [diff] [blame] | 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 DeviceSerializer extends SerializerBase<Device> { |
| 13 | |
| 14 | public DeviceSerializer() { |
| 15 | super(Device.class); |
| 16 | } |
| 17 | |
| 18 | @Override |
| 19 | public void serialize(Device dev, JsonGenerator jsonGenerator, |
Ray Milkey | 7d7f0a0 | 2014-06-18 12:52:13 -0700 | [diff] [blame] | 20 | SerializerProvider serializerProvider) throws IOException { |
Pavlin Radoslavov | 5cf1fe0 | 2014-07-03 22:52:25 -0700 | [diff] [blame^] | 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 DeviceEvent. |
| 25 | // In the future, we will use a single serializer. |
| 26 | // |
| 27 | |
TeruU | 65bc5ff | 2014-04-23 22:22:32 -0700 | [diff] [blame] | 28 | jsonGenerator.writeStartObject(); |
TeruU | 1c072a6 | 2014-04-28 14:49:25 -0700 | [diff] [blame] | 29 | jsonGenerator.writeStringField("mac", dev.getMacAddress().toString()); |
TeruU | 65bc5ff | 2014-04-23 22:22:32 -0700 | [diff] [blame] | 30 | jsonGenerator.writeFieldName("attachmentPoints"); |
| 31 | jsonGenerator.writeStartArray(); |
| 32 | for (Port port : dev.getAttachmentPoints()) { |
Pavlin Radoslavov | 5cf1fe0 | 2014-07-03 22:52:25 -0700 | [diff] [blame^] | 33 | jsonGenerator.writeObject(port.asSwitchPort()); |
TeruU | 65bc5ff | 2014-04-23 22:22:32 -0700 | [diff] [blame] | 34 | } |
| 35 | jsonGenerator.writeEndArray(); |
| 36 | jsonGenerator.writeEndObject(); |
| 37 | } |
TeruU | 65bc5ff | 2014-04-23 22:22:32 -0700 | [diff] [blame] | 38 | } |