blob: 3c368708a52ccec257c4d019934fccda63446e36 [file] [log] [blame]
Pavlin Radoslavov7c153612013-02-25 19:46:08 -08001package net.floodlightcontroller.util.serializers;
2
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
13import net.floodlightcontroller.util.IPv4Net;
14
15import org.slf4j.Logger;
16import org.slf4j.LoggerFactory;
17
18/**
Pavlin Radoslavovede97582013-03-08 18:57:28 -080019 * Deserialize an IPv4Net address from a string.
Pavlin Radoslavov7c153612013-02-25 19:46:08 -080020 */
21public class IPv4NetDeserializer extends JsonDeserializer<IPv4Net> {
22
23 protected static Logger log = LoggerFactory.getLogger(IPv4NetDeserializer.class);
24
25 @Override
26 public IPv4Net deserialize(JsonParser jp,
27 DeserializationContext ctxt)
28 throws IOException, JsonProcessingException {
29
30 IPv4Net ipv4Net = 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 ipv4Net = new IPv4Net(value);
39 }
40 }
41 return ipv4Net;
42 }
43}