blob: 0678d492b1b5c88edeae6bded3ddbf1540a49bce [file] [log] [blame]
Ray Milkey2fa6ca42014-06-13 15:38:20 -07001package net.onrc.onos.core.topology.web.serializers;
2
3import net.onrc.onos.core.topology.LinkEvent;
4import org.codehaus.jackson.JsonGenerator;
5import org.codehaus.jackson.map.SerializerProvider;
6import org.codehaus.jackson.map.ser.std.SerializerBase;
7
8import java.io.IOException;
9
10/**
11 * JSON serializer for LinkEvents.
12 */
13public 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 Radoslavov5cf1fe02014-07-03 22:52:25 -070036 //
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 Milkey2fa6ca42014-06-13 15:38:20 -070041
Pavlin Radoslavov5cf1fe02014-07-03 22:52:25 -070042 jsonGenerator.writeStartObject();
Ray Milkey2fa6ca42014-06-13 15:38:20 -070043 jsonGenerator.writeObjectField("src", linkEvent.getSrc());
44 jsonGenerator.writeObjectField("dst", linkEvent.getDst());
Ray Milkey2fa6ca42014-06-13 15:38:20 -070045 jsonGenerator.writeEndObject();
46 }
47}