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; |
| 6 | import net.onrc.onos.core.topology.Switch; |
Jonathan Hart | 891d050 | 2014-02-10 10:04:08 -0800 | [diff] [blame] | 7 | |
| 8 | import org.codehaus.jackson.JsonGenerator; |
| 9 | import org.codehaus.jackson.JsonProcessingException; |
| 10 | import org.codehaus.jackson.map.SerializerProvider; |
| 11 | import org.codehaus.jackson.map.ser.std.SerializerBase; |
| 12 | import org.openflow.util.HexString; |
| 13 | |
| 14 | public class SwitchSerializer extends SerializerBase<Switch> { |
| 15 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 16 | public SwitchSerializer() { |
| 17 | super(Switch.class); |
| 18 | } |
Jonathan Hart | 891d050 | 2014-02-10 10:04:08 -0800 | [diff] [blame] | 19 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 20 | @Override |
| 21 | public void serialize(Switch sw, JsonGenerator jsonGenerator, |
| 22 | SerializerProvider serializerProvider) throws IOException, |
| 23 | JsonProcessingException { |
| 24 | |
| 25 | jsonGenerator.writeStartObject(); |
| 26 | jsonGenerator.writeStringField("dpid", HexString.toHexString(sw.getDpid())); |
| 27 | jsonGenerator.writeStringField("state", "ACTIVE"); |
| 28 | jsonGenerator.writeArrayFieldStart("ports"); |
| 29 | for (Port port : sw.getPorts()) { |
| 30 | jsonGenerator.writeObject(port); |
| 31 | } |
| 32 | jsonGenerator.writeEndArray(); |
| 33 | jsonGenerator.writeEndObject(); |
| 34 | } |
Jonathan Hart | 891d050 | 2014-02-10 10:04:08 -0800 | [diff] [blame] | 35 | |
| 36 | } |