From: Kai Moritz Date: Sat, 7 Nov 2015 17:44:46 +0000 (+0100) Subject: WIP X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=1b756950afb4099d10403fd8d6b59425231f36a5;p=facebook-utils WIP --- diff --git a/src/main/java/de/juplo/facebook/exceptions/GraphApiException.java b/src/main/java/de/juplo/facebook/exceptions/GraphApiException.java index 9379abe..95bb4de 100644 --- a/src/main/java/de/juplo/facebook/exceptions/GraphApiException.java +++ b/src/main/java/de/juplo/facebook/exceptions/GraphApiException.java @@ -37,6 +37,7 @@ public class GraphApiException extends OAuth2Exception OBJECT_MAPPER.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); OBJECT_MAPPER.configure(DeserializationFeature.ACCEPT_FLOAT_AS_INT, false); OBJECT_MAPPER.configure(SerializationFeature.WRAP_ROOT_VALUE, true); + OBJECT_MAPPER.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); } diff --git a/src/test/java/de/juplo/facebook/exceptions/FacebookErrorMessageMappingTest.java b/src/test/java/de/juplo/facebook/exceptions/FacebookErrorMessageMappingTest.java index 3d672a4..64f51b2 100644 --- a/src/test/java/de/juplo/facebook/exceptions/FacebookErrorMessageMappingTest.java +++ b/src/test/java/de/juplo/facebook/exceptions/FacebookErrorMessageMappingTest.java @@ -7,6 +7,7 @@ import de.juplo.facebook.exceptions.GraphApiException.Type; import java.io.IOException; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; /** * @author Kai Moritz @@ -26,6 +27,8 @@ public class FacebookErrorMessageMappingTest "}" + "}"; + final String error_100 = "{\"error\":{\"message\":\"Unsupported get request. Please read the Graph API documentation at https:\\/\\/developers.facebook.com\\/docs\\/graph-api\",\"type\":\"GraphMethodException\",\"code\":100,\"fbtrace_id\":\"Bs\\/0p3CiVld\"}}"; + @Test public void testSerialize() throws JsonProcessingException @@ -42,6 +45,18 @@ public class FacebookErrorMessageMappingTest assertEquals(example, OBJECT_MAPPER.writeValueAsString(error)); } + @Test + public void testSerialize100() throws JsonProcessingException + { + FacebookErrorMessage error = new FacebookErrorMessage(); + error.message = "Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api"; + error.type = "GraphMethodException"; + error.code = 100; + error.traceId = "Bs/0p3CiVld"; + + assertEquals(error_100, OBJECT_MAPPER.writeValueAsString(error)); + } + @Test public void testDeserialize() throws IOException { @@ -56,4 +71,19 @@ public class FacebookErrorMessageMappingTest assertEquals("A message", error.userMessage); assertEquals("EJplcsCHuLu", error.traceId); } + + @Test + public void testDeserialize100() throws IOException + { + FacebookErrorMessage error = + OBJECT_MAPPER.readValue(error_100, FacebookErrorMessage.class); + + assertEquals("Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api", error.message); + assertEquals("GraphMethodException", error.type); + assertEquals(new Integer(100), error.code); + assertNull(error.subCode); + assertNull(error.userTitle); + assertNull(error.userMessage); + assertEquals("Bs/0p3CiVld", error.traceId); + } }