1 package de.juplo.facebook.exceptions;
4 import com.fasterxml.jackson.core.JsonParser;
5 import com.fasterxml.jackson.core.JsonProcessingException;
6 import com.fasterxml.jackson.core.JsonToken;
7 import com.fasterxml.jackson.databind.DeserializationContext;
8 import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
9 import java.io.IOException;
10 import java.util.HashMap;
18 public class GraphApiExceptionJackson2Deserializer
20 StdDeserializer<GraphApiException>
22 public GraphApiExceptionJackson2Deserializer()
24 super(GraphApiException.class);
28 public GraphApiException deserialize(
30 DeserializationContext ctxt
34 JsonProcessingException
36 JsonToken t = jp.getCurrentToken();
37 if (t != JsonToken.START_OBJECT)
41 if (t != JsonToken.FIELD_NAME)
44 if (!jp.getCurrentName().equals("error"))
48 if (t != JsonToken.START_OBJECT)
51 String message = null, type = null;
55 Map<String, String> map = new HashMap<>();
56 for (; t == JsonToken.FIELD_NAME; t = jp.nextToken())
58 // Must point to field name
59 String fieldName = jp.getCurrentName();
60 // And then the value...
66 switch(fieldName.toLowerCase())
69 message = jp.getText();
78 case VALUE_NUMBER_INT:
79 if (!fieldName.equalsIgnoreCase("code"))
81 code = jp.getValueAsInt();
88 if (message == null || type == null || code == null)
93 case 1: return new UnknownErrorException();
94 case 2: return new UnexpectedErrorException();
95 case 21: return new PageMigratedException(message);
96 case 100: return new UnsupportedGetRequestException();
97 case 613: return new RateExceededException();
98 default: return new GraphApiException(message, type, code);