Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.topology.serializers; |
Jonathan Hart | 891d050 | 2014-02-10 10:04:08 -0800 | [diff] [blame] | 2 | |
| 3 | import java.io.IOException; |
| 4 | |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 5 | import net.onrc.onos.core.topology.Port; |
Jonathan Hart | 891d050 | 2014-02-10 10:04:08 -0800 | [diff] [blame] | 6 | |
| 7 | import org.codehaus.jackson.JsonGenerator; |
| 8 | import org.codehaus.jackson.JsonProcessingException; |
| 9 | import org.codehaus.jackson.map.SerializerProvider; |
| 10 | import org.codehaus.jackson.map.ser.std.SerializerBase; |
| 11 | |
| 12 | public class PortSerializer extends SerializerBase<Port> { |
| 13 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 14 | public PortSerializer() { |
| 15 | super(Port.class); |
| 16 | } |
Jonathan Hart | 891d050 | 2014-02-10 10:04:08 -0800 | [diff] [blame] | 17 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 18 | @Override |
| 19 | public void serialize(Port port, JsonGenerator jsonGenerator, |
| 20 | SerializerProvider serializerProvider) |
| 21 | throws IOException, JsonProcessingException { |
| 22 | jsonGenerator.writeStartObject(); |
| 23 | jsonGenerator.writeStringField("state", "ACTIVE"); |
| 24 | jsonGenerator.writeNumberField("number", port.getNumber()); |
| 25 | jsonGenerator.writeStringField("desc", port.getDescription()); |
| 26 | jsonGenerator.writeArrayFieldStart("devices"); |
| 27 | jsonGenerator.writeEndArray(); |
| 28 | jsonGenerator.writeEndObject(); |
| 29 | } |
Jonathan Hart | 891d050 | 2014-02-10 10:04:08 -0800 | [diff] [blame] | 30 | |
| 31 | } |