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