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; |
| 7 | import org.openflow.util.HexString; |
| 8 | |
| 9 | import java.io.IOException; |
| 10 | |
| 11 | /** |
| 12 | * JSON Serializer for SwitchPorts. |
| 13 | */ |
| 14 | public class SwitchPortSerializer extends SerializerBase<SwitchPort> { |
| 15 | |
| 16 | /** |
| 17 | * Public constructor - just calls its super class constructor. |
| 18 | */ |
| 19 | public SwitchPortSerializer() { |
| 20 | super(SwitchPort.class); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Serializes a SwitchPort object. |
| 25 | * |
| 26 | * @param switchPort object to serialize |
| 27 | * @param jsonGenerator generator to add the serialized object to |
| 28 | * @param serializerProvider not used |
| 29 | * @throws IOException if the serialization fails |
| 30 | */ |
| 31 | @Override |
| 32 | public void serialize(final SwitchPort switchPort, |
| 33 | final JsonGenerator jsonGenerator, |
| 34 | final SerializerProvider serializerProvider) |
| 35 | throws IOException { |
| 36 | jsonGenerator.writeStartObject(); |
| 37 | |
| 38 | jsonGenerator.writeStringField("dpid", |
| 39 | HexString.toHexString(switchPort.getDpid())); |
| 40 | jsonGenerator.writeStringField("portNumber", |
| 41 | Long.toString(switchPort.getNumber())); |
| 42 | |
| 43 | jsonGenerator.writeEndObject(); |
| 44 | } |
| 45 | |
| 46 | } |