All,
I’m trying to do the following:
public class SomClass
{
public boolean x;
public int y;
public String z;
}
SomClass s = new SomClass();
s.x = true;
s.y = 10;
s.z = "ZZZ";
Gson gson = new Gson();
String retVal = gson.toJson(s);
return retVal;
So this little snippet will produce:
{"x":true,"y":10,"z":"ZZZ"}
but what I need it to produce is:
{"x":0, "y":10,"z":"ZZZ"}
Can someone please give me some options? I’d prefer not to rewrite my booleans as ints as that will cause several issues with existing code (nonobvious, hard to read, hard to enforce, etc.)
To make it “correct” way, you can use something like that
And then use it:
Hope this helps someone 🙂