+ try
+ {
+ return OBJECT_MAPPER.writeValueAsString(error);
+ }
+ catch(JsonProcessingException e)
+ {
+ // This should never happen. But in case of a mistake: be verbose!
+ LOG.error("could not convert message into JSON: {}", e);
+ return e.getMessage();
+ }
+ }
+
+
+ /**
+ * This class represents an error message from the Graph-API
+ *
+ * @see <a href="https://developers.facebook.com/docs/graph-api/using-graph-api/v2.5#errors">Graph-API Documentation</a>
+ */
+ @JsonRootName("error")
+ @JsonPropertyOrder({ "message", "type", "code", "error_subcode", "error_user_title", "error_user_msg", "fbtrace_id" })
+ public static class FacebookErrorMessage
+ {
+ @JsonProperty("message")
+ String message;
+ @JsonProperty("type")
+ String type;
+ @JsonProperty("code")
+ Integer code;
+ @JsonProperty("error_subcode")
+ Integer subCode;
+ @JsonProperty("error_user_title")
+ String userTitle;
+ @JsonProperty("error_user_msg")
+ String userMessage;
+ @JsonProperty("fbtrace_id")
+ String traceId;
+ }
+
+ public static class CustomCharacterEscapes extends CharacterEscapes
+ {
+ private final int[] _asciiEscapes;
+
+
+ public CustomCharacterEscapes()
+ {
+ _asciiEscapes = standardAsciiEscapesForJSON();
+ _asciiEscapes['/'] = CharacterEscapes.ESCAPE_CUSTOM;
+ }
+
+
+ @Override
+ public int[] getEscapeCodesForAscii()
+ {
+ return _asciiEscapes;
+ }
+
+ @Override
+ public SerializableString getEscapeSequence(int i)
+ {
+ if(i == '/')
+ {
+ return new SerializableString()
+ {
+ @Override
+ public String getValue()
+ {
+ return "\\/";
+ }
+
+ @Override
+ public int charLength()
+ {
+ return 2;
+ }
+
+ @Override
+ public char[] asQuotedChars()
+ {
+ return new char[]{'\\','/'};
+ }
+
+ @Override
+ public byte[] asUnquotedUTF8()
+ {
+ return new byte[]{'\\','/'};
+ }
+
+ @Override
+ public byte[] asQuotedUTF8()
+ {
+ return new byte[]{'\\','/'};
+ }
+
+ @Override
+ public int appendQuotedUTF8(byte[] buffer, int offset)
+ {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public int appendQuoted(char[] buffer, int offset)
+ {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public int appendUnquotedUTF8(byte[] buffer, int offset)
+ {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public int appendUnquoted(char[] buffer, int offset)
+ {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public int writeQuotedUTF8(OutputStream out) throws IOException
+ {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public int writeUnquotedUTF8(OutputStream out) throws IOException
+ {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public int putQuotedUTF8(ByteBuffer buffer) throws IOException
+ {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public int putUnquotedUTF8(ByteBuffer out) throws IOException
+ {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+ };
+ }
+ else
+ {
+ return null;
+ }
+ }