1 package de.juplo.facebook.exceptions;
3 import java.io.IOException;
4 import java.util.HashMap;
6 import org.codehaus.jackson.JsonParser;
7 import org.codehaus.jackson.JsonProcessingException;
8 import org.codehaus.jackson.JsonToken;
9 import org.codehaus.jackson.map.DeserializationContext;
10 import org.codehaus.jackson.map.JsonDeserializer;
15 public class GraphApiExceptionJackson1Deserializer
17 JsonDeserializer<GraphApiException>
21 public GraphApiException deserialize(
23 DeserializationContext ctxt
27 JsonProcessingException
29 JsonToken t = jp.getCurrentToken();
30 if (t != JsonToken.START_OBJECT)
34 if (t != JsonToken.FIELD_NAME)
37 if (!jp.getCurrentName().equals("error"))
41 if (t != JsonToken.START_OBJECT)
44 String message = null, type = null;
48 Map<String, String> map = new HashMap<>();
49 for (; t == JsonToken.FIELD_NAME; t = jp.nextToken())
51 // Must point to field name
52 String fieldName = jp.getCurrentName();
53 // And then the value...
59 switch(fieldName.toLowerCase())
62 message = jp.getText();
71 case VALUE_NUMBER_INT:
72 if (!fieldName.equalsIgnoreCase("code"))
74 code = jp.getValueAsInt();
81 if (message == null || type == null || code == null)
86 case 1: return new UnknownErrorException();
87 case 2: return new UnexpectedErrorException();
88 case 21: return new PageMigratedException(message);
89 case 100: return new UnsupportedGetRequestException();
90 case 613: return new RateExceededException();
91 default: return new GraphApiException(message, type, code);