Siehe: serialize
authorKai Moritz <kai@juplo.de>
Sat, 7 Nov 2015 17:51:13 +0000 (18:51 +0100)
committerKai Moritz <kai@juplo.de>
Tue, 10 Nov 2015 14:52:41 +0000 (15:52 +0100)
http://stackoverflow.com/questions/6817520/escape-forward-slash-in-jackson
http://wiki.fasterxml.com/CharacterEscapes
http://fasterxml.github.io/jackson-core/javadoc/2.1.0/index.html?com/fasterxml/jackson/core/io/CharacterEscapes.html

src/main/java/de/juplo/facebook/exceptions/GraphApiException.java

index 95bb4de..a01a9e1 100644 (file)
@@ -5,12 +5,16 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder;
 import com.fasterxml.jackson.annotation.JsonRootName;
 import com.fasterxml.jackson.core.JsonParseException;
 import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.SerializableString;
+import com.fasterxml.jackson.core.io.CharacterEscapes;
 import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.JsonMappingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.SerializationFeature;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
@@ -171,4 +175,115 @@ public class GraphApiException extends OAuth2Exception
     @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;
+      }
+    }
+  }
 }