blob: 47985b0be60164258300402596f23f91053e33c8 [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;
Yuta HIGUCHI1222ac52014-07-09 16:50:28 -07004import net.onrc.onos.core.topology.TopologyElement;
5
Ray Milkey2fa6ca42014-06-13 15:38:20 -07006import org.codehaus.jackson.JsonGenerator;
7import org.codehaus.jackson.map.SerializerProvider;
8import org.codehaus.jackson.map.ser.std.SerializerBase;
9
10import java.io.IOException;
11
12/**
13 * JSON serializer for LinkEvents.
14 */
15public 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 Radoslavov5cf1fe02014-07-03 22:52:25 -070038 //
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 Milkey2fa6ca42014-06-13 15:38:20 -070043
Pavlin Radoslavov5cf1fe02014-07-03 22:52:25 -070044 jsonGenerator.writeStartObject();
Yuta HIGUCHI1222ac52014-07-09 16:50:28 -070045 jsonGenerator.writeStringField(TopologyElement.TYPE, linkEvent.getType());
Ray Milkey2fa6ca42014-06-13 15:38:20 -070046 jsonGenerator.writeObjectField("src", linkEvent.getSrc());
47 jsonGenerator.writeObjectField("dst", linkEvent.getDst());
Ray Milkey2fa6ca42014-06-13 15:38:20 -070048 jsonGenerator.writeEndObject();
49 }
50}