1

I have an XML with a "token" field in it, in java it's:

@XmlElement(name = "Token", required = true)
protected byte[] token;

I'm using a UUID to generate the token, so I do:

UUID uuid=UUID.randomUUID();
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
bb.putLong(uuid.getMostSignificantBits());
bb.putLong(uuid.getLeastSignificantBits());
byte[] token = bb.array();   
myXML.setToken(token);

and in the XML I get something like that:

<Token>jvXrf8HvSVq23MiwSbnT+A==</Token>

I need also to send the token to a service that use Json notation, so in another funcion I get the token from the XML object and store it in a POJO:

String sToken = Base64.encode(myXML.getToken());
myPojo.setToken(sToken);

I've checked the string and it's correct, but when I convert myPojo to Json with Gson:

GsonBuilder gb = new GsonBuilder()
  .serializeNulls()
  .setPrettyPrinting()
  .setDateFormat("yyyy-MM-dd HH:mm:ss");
Gson gson = gb.create();
String json=gson.toJson(myPojo);

I get this in the json string representation of the object:

jvXrf8HvSVq23MiwSbnT+A\u003d\u003d

with the two "=" translated in "\u003d". It's normal? Do the \u003d code get translated to "=" at the receiving part?

Thank you

moretti.fabio
  • 1,128
  • 13
  • 32

1 Answers1

0

Yes, GSON changes = to unicode \u003d.

you can get details info here:

GSON issue with String

Disable escape HTML and then you are good to go.

Community
  • 1
  • 1
user3657302
  • 347
  • 1
  • 5