Make gson NOT put quotes in field names

Let's say I have a base class in Java:

public class Person{ public String name; } 

When I pass an object created with the name "bob" to serialize gson, it returns as:

 {"name" : "bob"} 

How can I do this to give me:

 {name:"bob"} 

I know this is a simple question, but I do not find anything that could help me in the API, and I apparently do not know the terminology suitable enough for json to search well enough to find an answer.

+6
source share
1 answer

Yes, as mentioned above, the JSON specification is awaiting a quote.

Now, if you really need your stuff, you can try creating your own JSONWriter and passing it to Gson.toJson(Object src, Type typeOfSrc, JsonWriter writer) throws JsonIOException

+2
source

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


All Articles