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.LinkEvent; |
Yuta HIGUCHI | 1222ac5 | 2014-07-09 16:50:28 -0700 | [diff] [blame^] | 4 | import net.onrc.onos.core.topology.TopologyElement; |
| 5 | |
Ray Milkey | 2fa6ca4 | 2014-06-13 15:38:20 -0700 | [diff] [blame] | 6 | import org.codehaus.jackson.JsonGenerator; |
| 7 | import org.codehaus.jackson.map.SerializerProvider; |
| 8 | import org.codehaus.jackson.map.ser.std.SerializerBase; |
| 9 | |
| 10 | import java.io.IOException; |
| 11 | |
| 12 | /** |
| 13 | * JSON serializer for LinkEvents. |
| 14 | */ |
| 15 | public class LinkEventSerializer extends SerializerBase<LinkEvent> { |
| 16 | |
| 17 | /** |
| 18 | * Public constructor - just calls its super class constructor. |
| 19 | */ |
| 20 | public LinkEventSerializer() { |
| 21 | super(LinkEvent.class); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Serializes a LinkEvent object. |
| 26 | * |
| 27 | * @param linkEvent LinkEvent to serialize |
| 28 | * @param jsonGenerator generator to add the serialized object to |
| 29 | * @param serializerProvider not used |
| 30 | * @throws IOException if the JSON serialization fails |
| 31 | */ |
| 32 | @Override |
| 33 | public void serialize(final LinkEvent linkEvent, |
| 34 | final JsonGenerator jsonGenerator, |
| 35 | final SerializerProvider serializerProvider) |
| 36 | throws IOException { |
| 37 | |
Pavlin Radoslavov | 5cf1fe0 | 2014-07-03 22:52:25 -0700 | [diff] [blame] | 38 | // |
| 39 | // TODO: For now, the JSON format of the serialized output should |
| 40 | // be same as the JSON format of the corresponding class Link. |
| 41 | // In the future, we will use a single serializer. |
| 42 | // |
Ray Milkey | 2fa6ca4 | 2014-06-13 15:38:20 -0700 | [diff] [blame] | 43 | |
Pavlin Radoslavov | 5cf1fe0 | 2014-07-03 22:52:25 -0700 | [diff] [blame] | 44 | jsonGenerator.writeStartObject(); |
Yuta HIGUCHI | 1222ac5 | 2014-07-09 16:50:28 -0700 | [diff] [blame^] | 45 | jsonGenerator.writeStringField(TopologyElement.TYPE, linkEvent.getType()); |
Ray Milkey | 2fa6ca4 | 2014-06-13 15:38:20 -0700 | [diff] [blame] | 46 | jsonGenerator.writeObjectField("src", linkEvent.getSrc()); |
| 47 | jsonGenerator.writeObjectField("dst", linkEvent.getDst()); |
Ray Milkey | 2fa6ca4 | 2014-06-13 15:38:20 -0700 | [diff] [blame] | 48 | jsonGenerator.writeEndObject(); |
| 49 | } |
| 50 | } |