Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with parsing array of nulls #2

Open
andrewpang opened this issue Oct 10, 2016 · 1 comment
Open

Problem with parsing array of nulls #2

andrewpang opened this issue Oct 10, 2016 · 1 comment

Comments

@andrewpang
Copy link

andrewpang commented Oct 10, 2016

When the JSON provided from the server is an Array that contains nulls, for example:
screen shot 2016-10-10 at 3 32 01 pm

this exception is thrown:

Caused by: java.lang.IllegalStateException: Could not convert value in array at "addressLines" to java.lang.Object from null.

This seems to happen because in the method parseFlatJsonArray, under the file JsonParserUtils.java, there's this code that throws an exception, since null is never an instance of Object.

if (typeClass.isInstance(nextValue)) {
                // This is safe since we are calling class.isInstance()
                @SuppressWarnings("unchecked")
                T toAdd = (T) nextValue;
                collection.add(toAdd);
            } else {
                throw new IllegalStateException(
                        String.format(Locale.US,
                                      "Could not convert value in array at \"%s\" to %s from %s.",
                                      key,
                                      typeClass.getCanonicalName(),
                                      getClassName(nextValue)));
            }

So Nathan, I wanted to ask your opinion of whether we should change this code to pass over the nulls and not throw an exception here, or if we need to leave it like this because it's expected to throw an exception if there are null values.

@ndtaylor
Copy link
Contributor

I don't think there would be any problem with allowing nulls in Collections. The only issue you might run into is if the Collection in question does not allow nulls as items, but then the client at least has the object to use a different implementation of Collection.

We would also need to make sure that a null in a Collection of Collections is allowed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants