Ray Milkey | 2fa6ca4 | 2014-06-13 15:38:20 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.topology.web.serializers; |
| 2 | |
| 3 | import net.onrc.onos.core.topology.PortEvent.SwitchPort; |
| 4 | import org.codehaus.jackson.JsonGenerator; |
| 5 | import org.codehaus.jackson.map.SerializerProvider; |
| 6 | import org.codehaus.jackson.map.ser.std.SerializerBase; |
Ray Milkey | 2fa6ca4 | 2014-06-13 15:38:20 -0700 | [diff] [blame] | 7 | import java.io.IOException; |
| 8 | |
| 9 | /** |
| 10 | * JSON Serializer for SwitchPorts. |
| 11 | */ |
| 12 | public class SwitchPortSerializer extends SerializerBase<SwitchPort> { |
| 13 | |
| 14 | /** |
| 15 | * Public constructor - just calls its super class constructor. |
| 16 | */ |
| 17 | public SwitchPortSerializer() { |
| 18 | super(SwitchPort.class); |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Serializes a SwitchPort object. |
| 23 | * |
| 24 | * @param switchPort object to serialize |
| 25 | * @param jsonGenerator generator to add the serialized object to |
| 26 | * @param serializerProvider not used |
| 27 | * @throws IOException if the serialization fails |
| 28 | */ |
| 29 | @Override |
| 30 | public void serialize(final SwitchPort switchPort, |
| 31 | final JsonGenerator jsonGenerator, |
| 32 | final SerializerProvider serializerProvider) |
| 33 | throws IOException { |
| 34 | jsonGenerator.writeStartObject(); |
| 35 | |
| 36 | jsonGenerator.writeStringField("dpid", |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame^] | 37 | switchPort.getDpid().toString()); |
Ray Milkey | 2fa6ca4 | 2014-06-13 15:38:20 -0700 | [diff] [blame] | 38 | jsonGenerator.writeStringField("portNumber", |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame^] | 39 | switchPort.getNumber().toString()); |
Ray Milkey | 2fa6ca4 | 2014-06-13 15:38:20 -0700 | [diff] [blame] | 40 | |
| 41 | jsonGenerator.writeEndObject(); |
| 42 | } |
| 43 | |
| 44 | } |