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

@JsonProperty(access=READ_ONLY) unxepected behaviour with Collections #1382

Closed
hexfaker opened this issue Sep 22, 2016 · 2 comments
Closed
Milestone

Comments

@hexfaker
Copy link

I encountered problem same to #935, but it also affects 2.8.3, and related to collection properties deserialization.
Here reproducing test case, and it fails:

public class JacksonBugReproduction {
    private static class Foo {
        @JsonProperty(access = READ_ONLY)
        private List<Long> list = new ArrayList<>();

        List<Long> getList() {
            return list;
        }

        public Foo setList(List<Long> list) {
            this.list = list;
            return this;
        }
    }

    @Test
    public void shouldNotDeserializeList() throws Exception {
        String payload = "{\"list\":[1,2,3,4]}";
        ObjectMapper mapper = new ObjectMapper();

        Foo foo = mapper.readValue(payload, Foo.class);

        Assert.assertTrue("List should be empty", foo.getList().isEmpty());
    }
}

Full project project available here .

@hexfaker
Copy link
Author

OK, I disabled USE_GETTERS_AS_SETTERS feature, and now it works as expected. But I think this behavior is at least subject to discuss, if not wrong at all.

@cowtowncoder
Copy link
Member

@hexfaker That sounds like a bug to me: READ_ONLY should mean that no deserialization would be done. getters-as-setters feature itself is.... gnarly.... but it's due to JAXB legacy, where that's how all Collections are handled; and it usually should only occur if no real setter exists (and only for collections and maps). This should not, still, be a back door.

So, thank you for reporting this: as I said it looks like a bug to me.

@cowtowncoder cowtowncoder changed the title @JsonProperty(access=READ_ONLY) unxepected behaviour with collections @JsonProperty(access=READ_ONLY) unxepected behaviour with collections Oct 5, 2016
cowtowncoder added a commit that referenced this issue Oct 31, 2016
@cowtowncoder cowtowncoder added this to the 2.9.4 milestone Jan 24, 2018
@cowtowncoder cowtowncoder changed the title @JsonProperty(access=READ_ONLY) unxepected behaviour with collections @JsonProperty(access=READ_ONLY) unxepected behaviour with Collections Jan 24, 2018
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