You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the current implementation, when we deserialize a JSON string to an object the Unicode character conversion is converted to the Unicode character. For example \u0161 is converted to š. As a result, when we serialize back to JSON we get the Unicode character instead of the Unicode character conversion. Even though both strings \u0161 and š are valid and the same, it's better to have the option to preserve the original string(\u0161) when we serialize back.
Feature description
Add an option that will preserve \u0161 as it when we deserialize or serialize back to JSON
The text was updated successfully, but these errors were encountered:
Could you say a bit more about your use case? This option would remove the property that if you deserialize and then reserialize again you get back the original string, unless we also had an option to treat the six characters \u0161 in a string as actually being š.
Let's say the client needs to modify(add new child item_value) the following JSON payload using our application.
{
"item_name":"\u0161anme",
}
We deserialize the JSON string, update the object and return the serialized JSON string back to the client. Here the serialized JSON string will look like follows (\u0161 converted to š),
{
"item_name":"šanme",
"item_value": 55
}
We should ideally send back to the client the same JSON string they input.
The Gson API, especially JsonReader which is used by many of the other classes, only returns plain String values. There is no way to attach additional metadata to it such as which chars were originally Unicode-encoded in the JSON data.
Maybe the closest existing feature request is #1368 which might allow reading the string value as it is from the JSON data without interpreting any escape sequences. Though on the other hand that also means that if you wanted to not only preserve the original JSON string value, but also process it in some way, you would have to handle the escape sequences yourself.
Problem solved by the feature
In the current implementation, when we deserialize a JSON string to an object the Unicode character conversion is converted to the Unicode character. For example
\u0161
is converted toš
. As a result, when we serialize back to JSON we get the Unicode character instead of the Unicode character conversion. Even though both strings\u0161
andš
are valid and the same, it's better to have the option to preserve the original string(\u0161
) when we serialize back.Feature description
Add an option that will preserve
\u0161
as it when we deserialize or serialize back to JSONThe text was updated successfully, but these errors were encountered: