blob: 7a15ddcc71354e7d14fe0028c104837e97413e13 [file] [log] [blame]
HIGUCHI Yutaf086d8a2013-06-12 15:26:35 -07001package net.onrc.onos.ofcontroller.util.serializers;
Pavlin Radoslavov7c153612013-02-25 19:46:08 -08002
3import java.io.IOException;
4
5import org.codehaus.jackson.JsonNode;
6import org.codehaus.jackson.JsonParser;
7import org.codehaus.jackson.JsonToken;
8import org.codehaus.jackson.JsonProcessingException;
9import org.codehaus.jackson.ObjectCodec;
10import org.codehaus.jackson.map.JsonDeserializer;
11import org.codehaus.jackson.map.DeserializationContext;
12
HIGUCHI Yuta356086e2013-06-12 15:21:19 -070013import net.onrc.onos.ofcontroller.util.FlowEntryId;
Pavlin Radoslavov7c153612013-02-25 19:46:08 -080014
15import org.slf4j.Logger;
16import org.slf4j.LoggerFactory;
17
18/**
19 * Deserialize a Flow Entry ID from a string.
20 */
21public class FlowEntryIdDeserializer extends JsonDeserializer<FlowEntryId> {
22
23 protected static Logger log = LoggerFactory.getLogger(FlowEntryIdDeserializer.class);
24
25 @Override
26 public FlowEntryId deserialize(JsonParser jp,
27 DeserializationContext ctxt)
28 throws IOException, JsonProcessingException {
29
30 FlowEntryId flowEntryId = null;
31
32 jp.nextToken(); // Move to JsonToken.START_OBJECT
33 while (jp.nextToken() != JsonToken.END_OBJECT) {
34 String fieldname = jp.getCurrentName();
35 if ("value".equals(fieldname)) {
36 String value = jp.getText();
37 log.debug("Fieldname: " + fieldname + " Value: " + value);
38 flowEntryId = new FlowEntryId(value);
39 }
40 }
41 return flowEntryId;
42 }
43}