Gson converting a password with = symbol into JSON

I use Gson in an Android application to convert a complex object to a JSON representation. One of the fields is the QuickPin line containing the encrypted password, and the "=" character is converted to "\ 003d" from Gson.

The Json string is consumed by the C # WEBAPI application, but returns the error message "<message>.

The following JSON returns this error message:

{"UserContractID":"929c1399-11c4-490e-8cff-5b1458ac18e2","UserAuthentication":"MethodCombo":{"AuthMethod":[1]},"QuickPin":"mW2n2uTECEtVqWA2B9MzvQ\u003d\u003d"},"CustomerID":0,"OriginID":0,"OriginTypeID":0,"Status":0}

Meanwhile, this JSON works fine:

{"UserContractID":"929c1399-11c4-490e-8cff-5b1458ac18e2","UserAuthentication":{"QuickPin":"mW2n2uTECEtVqWA2B9MzvQ==","MethodCombo":{"AuthMethod":[1]}},"CustomerID":0,"OriginID":0,"OriginTypeID":0,"Status":0}

Is there a way to get Gson to support a password string with the characters = (and others, if so)?

My Android code:

Gson gson = new Gson();
user = new User();
user.UserAuthentication = new UserAuthentication();
user.UserAuthentication.QuickPin = "mW2n2uTECEtVqWA2B9MzvQ==";
user.UserAuthentication.MethodCombo = new MethodCombo();
user.UserAuthentication.MethodCombo.AuthMethod = new ArrayList<Integer>();
user.UserAuthentication.MethodCombo.AuthMethod.add(1);
user.Status = 0;
String jsonRepresentation = gson.toJson(user);
object.put("user", jsonRepresentation);

thank

+4
source share
1 answer

Gson HTML . .

Gson gson = new GsonBuilder().disableHtmlEscaping().create();
+6

Source: https://habr.com/ru/post/1529905/


All Articles