Open GoogleCodeExporter opened 9 years ago
This is very annoying to me.
We designed a format with many optional fields (lists in different types), and
it shows all these empty optional fields.
Original comment by Charles....@gmail.com
on 1 Jul 2013 at 2:26
Possible solution?
public String toJson(Object src, Type typeOfSrc) {
StringWriter writer = new StringWriter();
toJson(src, typeOfSrc, writer);
String jsonObject = writer.toString();
if (src instanceof ArrayList) {
if(jsonObject.contains("[")){
int index = jsonObject.indexOf("[");
char nextChar = jsonObject.charAt(index + 1);
if(nextChar == ']'){
jsonObject = null;
}
}
}
return jsonObject;
}
Original comment by Ewerto...@gmail.com
on 20 Aug 2013 at 1:44
I have a tangentially related issue. I feel that it is unnecessary to start a
new case so I'll write it here.
Sometimes I receive a -1 or 0 for when the Json array contains nothing. For
example, usually there might be a field "api_array":[1,2,3], but when the array
has nothing I get "api_array":-1 instead.
Currently I'm using a workaround as suggested by the folks on StackOverflow,
but I feel that there should be some elegant way of telling Gson that "If the
expected array has only 1 field or nothing, skip it or otherwise mark it as
blank".
Perhaps a flag in GsonBuilder?
Original comment by undisputed.seraphim
on 16 Dec 2013 at 10:08
Original issue reported on code.google.com by
chanda...@gmail.com
on 1 May 2013 at 5:25