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