Yuta HIGUCHI | a7f1cdd | 2014-06-09 15:05:20 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.topology.web.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.Link; |
Jonathan Hart | 891d050 | 2014-02-10 10:04:08 -0800 | [diff] [blame] | 6 | |
| 7 | import org.codehaus.jackson.JsonGenerationException; |
| 8 | import org.codehaus.jackson.JsonGenerator; |
| 9 | import org.codehaus.jackson.map.SerializerProvider; |
| 10 | import org.codehaus.jackson.map.ser.std.SerializerBase; |
| 11 | import org.openflow.util.HexString; |
| 12 | |
| 13 | public class LinkSerializer extends SerializerBase<Link> { |
| 14 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 15 | public LinkSerializer() { |
| 16 | super(Link.class); |
| 17 | } |
Jonathan Hart | 891d050 | 2014-02-10 10:04:08 -0800 | [diff] [blame] | 18 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 19 | @Override |
| 20 | public void serialize(Link link, JsonGenerator jsonGenerator, |
| 21 | SerializerProvider serializerProvider) |
| 22 | throws IOException, JsonGenerationException { |
| 23 | jsonGenerator.writeStartObject(); |
| 24 | jsonGenerator.writeStringField("src-switch", |
| 25 | HexString.toHexString(link.getSrcSwitch().getDpid())); |
| 26 | jsonGenerator.writeNumberField("src-port", |
| 27 | link.getSrcPort().getNumber()); |
| 28 | jsonGenerator.writeStringField("dst-switch", |
| 29 | HexString.toHexString(link.getDstSwitch().getDpid())); |
| 30 | jsonGenerator.writeNumberField("dst-port", |
| 31 | link.getDstPort().getNumber()); |
| 32 | jsonGenerator.writeEndObject(); |
| 33 | } |
Jonathan Hart | 891d050 | 2014-02-10 10:04:08 -0800 | [diff] [blame] | 34 | |
| 35 | } |