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

Fix for parsing "null" values for auto-value objects. #23

Closed
wants to merge 5 commits into from

Conversation

radzio
Copy link

@radzio radzio commented Apr 11, 2016

No description provided.

@rharter
Copy link
Owner

rharter commented Apr 13, 2016

Thanks for the PR. It looks like this caused the tests to fail, and also needs tests for your addition.

@radzio
Copy link
Author

radzio commented Apr 14, 2016

@rharter no problem. I didn't updated tests for this. But I've tested it manually and it's working like a charm :-)

@rharter
Copy link
Owner

rharter commented Apr 20, 2016

@radzio Are you planning to add tests for your changes? I won't be merging in untested code.

@R4md4c
Copy link
Contributor

R4md4c commented Apr 29, 2016

Hello @radzio,

Are you planning to add tests for this fix? I'm interested in merging this PR. If you don't have time I can step in to write the tests.

@rharter
Copy link
Owner

rharter commented May 11, 2016

@R4md4c Are you still up for writing tests for this and rebasing it?

@R4md4c
Copy link
Contributor

R4md4c commented May 11, 2016

@rharter Yes, I'm still up for it, but I'm wondering whether I should open a new pull request or I use the current pull request?

@rharter
Copy link
Owner

rharter commented May 11, 2016

You can always check out his branch into your own fork and make a new PR.

@muddin1
Copy link

muddin1 commented May 11, 2016

@rharter I use nullSafe() in my custom AutoValueTypeAdapterFactory, but now that AutoValueGsonTypeAdapterFactory is introduced in 0.3.0, I can't really use the generated implementation because it doesn't include nullSafe(). Is this pull request going to fix that?

@R4md4c
Copy link
Contributor

R4md4c commented May 15, 2016

I tried to write a test for this PR before applying the patch (after rebasing with upstream) to check what problem it does solve, but I realized that it doesn't solve anything when trying to read a null auto value object from the JSON string as it reads it without a problem.

Perhaps I misunderstood what problem this PR solves?

Here is the test method

   @Test
    public void testReadingNullAutoValueObject() throws Exception {
        Gson gson = new GsonBuilder()
                .registerTypeAdapterFactory(new PersonTypeAdapterFactory())
                .create();
        Person person = Person.builder()
                .name("Piasy")
                .gender(1)
                .age(23)
                .build();
        // Notice the null facility. 
        String fromJson = "{\"name\":\"Piasy\",\"gender\":1,\"age\":23,\"facility\":null}";
        Person fromJsonPerson = gson.fromJson(fromJson, Person.class);

        Assert.assertEquals(person, fromJsonPerson);
        Assert.assertNull(person.facility());
    }

Here is what I added to the Person class.

   @Nullable
    public abstract Facility facility(); // An AutoValue object that contains an integer.

ansman pushed a commit to ansman/auto-value-gson that referenced this pull request Oct 24, 2016
ansman added a commit to ansman/auto-value-gson that referenced this pull request Oct 24, 2016
ansman added a commit to ansman/auto-value-gson that referenced this pull request Oct 24, 2016
@rharter rharter closed this in #78 Oct 25, 2016
rharter pushed a commit that referenced this pull request Oct 25, 2016
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

Successfully merging this pull request may close these issues.

None yet

4 participants