Exclude empty array in Gson serialization
- Dominant language
- Java
- Stars
- 24.2k
- Forks
- 4.5k
- Avg merge
- 6d 4h
- Merged PRs (30d)
- 12
Description
```
What steps will reproduce the problem?
1. In Java class, define an attribute as List
private List Scores = new ArrayList();
2. If Score (ArrayList) is not populated or empty, while generating JSON file,
an empty array is getting generated
],
"scores": []
},
What is the expected output? What do you see instead?
Option 1 - If a collection or an array is empty, it should not generate an
empty array.
Example - com.google.gson.internal.bind.CollectionTypeAdapterFactory.write()
existing code - if (collection == null) {
expected - if (collection == null || collection.size() < 1) {
Option 2 - configuration property to enable/disable adding empty array, similar
to Jackon SerializationFeature.WRITE_EMPTY_JSON_ARRAYS
(http://wiki.fasterxml.com/JacksonFeaturesSerialization)
What version of the product are you using? On what operating system?
version 2.2.3
operating system - Mac OSX 10.8.3
Please provide any additional information below.
```
Original issue reported on code.google.com by `chanda...@gmail.com` on 1 May 2013 at 5:25
Contributor guide
Assessment
This issue has not been assessed yet.