Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.util.serializers; |
Pavlin Radoslavov | 7c15361 | 2013-02-25 19:46:08 -0800 | [diff] [blame] | 2 | |
| 3 | import java.io.IOException; |
| 4 | |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 5 | import net.onrc.onos.core.util.FlowEntryId; |
Pavlin Radoslavov | 7c15361 | 2013-02-25 19:46:08 -0800 | [diff] [blame] | 6 | |
HIGUCHI Yuta | 858c1ea | 2013-06-14 13:10:06 -0700 | [diff] [blame] | 7 | import org.codehaus.jackson.JsonParser; |
| 8 | import org.codehaus.jackson.JsonProcessingException; |
| 9 | import org.codehaus.jackson.JsonToken; |
| 10 | import org.codehaus.jackson.map.DeserializationContext; |
| 11 | import org.codehaus.jackson.map.JsonDeserializer; |
Pavlin Radoslavov | 7c15361 | 2013-02-25 19:46:08 -0800 | [diff] [blame] | 12 | import org.slf4j.Logger; |
| 13 | import org.slf4j.LoggerFactory; |
| 14 | |
| 15 | /** |
| 16 | * Deserialize a Flow Entry ID from a string. |
| 17 | */ |
| 18 | public class FlowEntryIdDeserializer extends JsonDeserializer<FlowEntryId> { |
| 19 | |
Ray Milkey | ec83894 | 2014-04-09 11:28:43 -0700 | [diff] [blame] | 20 | private static final Logger log = LoggerFactory.getLogger(FlowEntryIdDeserializer.class); |
Pavlin Radoslavov | 7c15361 | 2013-02-25 19:46:08 -0800 | [diff] [blame] | 21 | |
| 22 | @Override |
| 23 | public FlowEntryId deserialize(JsonParser jp, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 24 | DeserializationContext ctxt) |
| 25 | throws IOException, JsonProcessingException { |
Pavlin Radoslavov | 7c15361 | 2013-02-25 19:46:08 -0800 | [diff] [blame] | 26 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 27 | FlowEntryId flowEntryId = null; |
Pavlin Radoslavov | 7c15361 | 2013-02-25 19:46:08 -0800 | [diff] [blame] | 28 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 29 | jp.nextToken(); // Move to JsonToken.START_OBJECT |
| 30 | while (jp.nextToken() != JsonToken.END_OBJECT) { |
| 31 | String fieldname = jp.getCurrentName(); |
| 32 | if ("value".equals(fieldname)) { |
| 33 | String value = jp.getText(); |
| 34 | log.debug("Fieldname: " + fieldname + " Value: " + value); |
| 35 | flowEntryId = new FlowEntryId(value); |
| 36 | } |
| 37 | } |
| 38 | return flowEntryId; |
Pavlin Radoslavov | 7c15361 | 2013-02-25 19:46:08 -0800 | [diff] [blame] | 39 | } |
| 40 | } |