I have a custom JSON serializer with two fields, one string and one double. I have a requirement to have my output look like this:
[
{
"name":"name",
"value":3.0
},
{
"name":"name2",
"value":3.5
}
]
But right now it looks like this:
[
{
"name":"name",
"value":3
},
{
"name":"name2",
"value":3.5
}
]
My serialization code looks like this:
gen.writeStringField("name",movie.getName());
gen.writeNumberField("value",movie.getAverageRating()); // double type
I can make the field value to be String type and use something like:
gen.writeStringField("value",String.format("%.1f", movie.getAverageRating()));
but then the value of field "value" will have double qoutes and will by of type String and not number. So my question is: is it even possible to achieve the requirement which I mentioned at the begining?