Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.util.serializers; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | |
| 5 | import org.codehaus.jackson.JsonGenerator; |
| 6 | import org.codehaus.jackson.JsonProcessingException; |
| 7 | import org.codehaus.jackson.map.JsonSerializer; |
| 8 | import org.codehaus.jackson.map.SerializerProvider; |
| 9 | |
| 10 | import net.floodlightcontroller.util.DataPath; |
| 11 | import net.floodlightcontroller.util.FlowEntry; |
| 12 | |
| 13 | /** |
| 14 | * Serialize a DataPath as a string. |
| 15 | */ |
| 16 | public class DataPathSerializer extends JsonSerializer<DataPath> { |
| 17 | |
| 18 | @Override |
| 19 | public void serialize(DataPath dataPath, |
| 20 | JsonGenerator jGen, SerializerProvider serializer) |
| 21 | throws IOException, JsonProcessingException { |
| 22 | jGen.writeStartObject(); |
| 23 | jGen.writeObjectField("srcPort", dataPath.srcPort()); |
| 24 | jGen.writeArrayFieldStart("flowEntries"); |
| 25 | for (FlowEntry fe: dataPath.flowEntries()) { |
| 26 | jGen.writeObject(fe); |
| 27 | } |
| 28 | jGen.writeEndArray(); |
| 29 | jGen.writeObjectField("dstPort", dataPath.dstPort()); |
| 30 | jGen.writeEndObject(); |
| 31 | } |
| 32 | } |