Closed ibtesammalik closed 2 years ago
If the \u0060
appears like this in JSON and is not escaped with an additional backslash (e.g. \\u0060
), then it represents the Unicode code point U+0060, and Gson can just output the character (`
). Both JSON strings "... \u0060 ..."
and "... ` ..."
are valid and represent the same data.
Is there a reason why you need to have the Unicode escape \u0060
in the JSON output? Are you working with an external library which does not support `
?
The current behaviour seems correct, as explained by @Marcono1234.
If the
\u0060
appears like this in JSON and is not escaped with an additional backslash (e.g.\\u0060
), then it represents the Unicode code point U+0060, and Gson can just output the character (`
). Both JSON strings"... \u0060 ..."
and"... ` ..."
are valid and represent the same data.Is there a reason why you need to have the Unicode escape
\u0060
in the JSON output? Are you working with an external library which does not support`
?
no, I am not using a third library, the reason I need this is because I am going to encrypt complete JSON data and send an encrypted signatory, like this
{
"data":{"consignorAddress":"POL IND AMETLLA PARK CALLE AIGUAFREDA, 12 LAMETLLA DEL VALLES,08480 BARCELONA SPAIN NIF: ES G63059521"}, "signature":"qdfi4BnDBXA1OMotX0TkwRSRQzJ1QhHBgEe4g7Q7EAE=" } if I encrypt data with " ' " then the client will not enable to validate my signatory. because the client is expecting
\u0060`
Which library are you using on the client to extract "data"
from the JSON document? To me it sounds like you would also have to verify that client and server extract "data"
in the same way from the JSON. Would it be possible to transmit the "data"
value separately to the client, so the client would not have to extract it itself, and to prevent any conversion mismatches such as the one you are currently experiencing?
Note that Gson might also not be able to preserve the exact formatting (at least in case the JSON is formatted / pretty-printed in some way).
Gson version
GSON version auto fetches by using spring boot2.0.9.RELEASE
Java / Android version
JDK 1.8
Used tools
Description
Expected behavior
{"data":{"consignorAddress":"POL IND AMETLLA PARK CALLE AIGUAFREDA, 12 L\u0060AMETLLA DEL VALLES,08480 BARCELONA SPAIN NIF: ES G63059521"}}
Actual behavior
data:{"consignorAddress":"POL IND AMETLLA PARK CALLE AIGUAFREDA, 12 L`AMETLLA DEL VALLES,08480 BARCELONA SPAIN NIF: ES G63059521"}
Reproduction steps
String data ="{\"data\":{\"consignorAddress\":\"POL IND AMETLLA PARK CALLE AIGUAFREDA, 12 L\u0060AMETLLA DEL VALLES,08480 BARCELONA SPAIN NIF: ES G63059521\"}}";
Gson gson = new GsonBuilder().create();