Reputation: 123
I'm converting my object to JSON in Android using Gson.toJson(object) but for some reason it is adding a \n
to the end of one of the properties in the object. Any help? Thank you.
My object is a ticket.
Logging the TicketId property value returns:
7NyzwRaic5xGgDRm9r1s6u+C1hQ/fOVOp+a5hlIYjJOdctPKOQAses0qRdy2RaZr
Using:
Gson gson = new Gson();
String json = gson.toJson(ticket);
Logging the output JSON returns this:
json: {"UserEmail":"[email protected]","TicketId":"7NyzwRaic5xGgDRm9r1s6u+C1hQ/fOVOp+a5hlIYjJOdctPKOQAses0qRdy2RaZr\n","Used":false,"EventPrice":0.0,"EventId":0}
You can see there is a "\n" added at the end of the TicketId property value.
Upvotes: 1
Views: 2360
Reputation: 123
I found the solution. Android's built in Base64 utility adds a New Line to the end of a string and I am getting the ticketID using said utility. I had to set the flag for converting the bytes to a string using the Base64.NO_WRAP
flag.
I have no idea why it wasn't showing up in the logcat for the ticketId.
Basic authentication to access assembla rest apis from android
Upvotes: 7