Conversation
|
the StringEscapeUtil.unescape method seems not working for the above specific case. output from the escape util: expected: the back slash will not stay if we are using unescape method |
|
Again, tried with the StringEscapeUtil.unescape(), it seems not working, the json decoder will be confused about the first double quote it gets. and to be clear: current fix will return \ "test \ \ \ ", \ " -> looks like -> " test ", " to the api caller with the jsonescaper, it will return as |
| private static final char KEY_DELIMITER = ':'; | ||
| private static final char PAIR_DELIMITER = ','; | ||
| private static final char KEY_BARRIER = '"'; | ||
| private static final char KEY_ESCAPER = 92; // the backslash value |
There was a problem hiding this comment.
Using an int value here will work since they are interchangeable. However, considering the readability and consistency (with other char const value above), will it be better to use the char value? Or any specific reason to use int value instead?
|
|
||
| Zoo zoo = new Json().decode(serializedZoo, Zoo.class); | ||
|
|
||
| assertEquals(zoo.name, "test \\\", "); |
There was a problem hiding this comment.
To test whether your parsing is correct, in this test it should include:
- create object
- serialize the object to string
- deserialize the string to object
- compare the objects in step 1 and 3, they should be identical.
|
@p1ngle hey Peng, just resolve the comments, can you check now? thanks ! |
| private static final char KEY_DELIMITER = ':'; | ||
| private static final char PAIR_DELIMITER = ','; | ||
| private static final char KEY_BARRIER = '"'; | ||
| private static final char KEY_ESCAPER = 92; // '/' the backslash value |
this is related to a paypal existing bug, where the Java SDK can not deserialize certain response
where the customer input the given string in the request
"C/ Dinamarca "IPEX", 2"
And in order to send the string correctly, the SDK caller need to escape the special character,
the input string will have to be
"C/ Dinamarca \ \ \ "IPEX \ \ \ ", 2"
SDK will escape one backslash, and send the following to the API
"C/ Dinamarca \ "IPEX \ ", 2"
when the API successfully process the request, it will send
"C/ Dinamarca \ \ \ "IPEX \ \ \ ", 2 "
when we deserialize the JSON string, we are using the double quote as the ending indicator, However, it will fail if the responses contain a double quote that is supposed to be escaped, and thus only process "C/ Dinamarca \ \ \ " instead of the whole string.