Deserialize JSON: Array sometimes NULL

I a JSON response I have an Array as follows: "colors": [ "Blue", "Black", "Green" ], I can deserialize this just fine using the Primitive solution from the REST Module. However sometimes a product has no colors and the JSON response looks like this: "colors": null, Is there a way for me to handle this? I get an error telling me that 'Colors' is not an Array (because it is empty). Is there any adjustment that can be made to the code to skip these parts, or does that cause other problems.
1 answers

Yes you can. Take a look at around line 115. The section that has a comment:


could be wrapped in something like this:

if (!object.isNull(attr) && object.getJSONArray(attr).length() > 0) {

which would cause the deserializer to skip that null attribute and continue on.