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 fails with collections when a property name is specified #2283

Closed
Yona-Appletree opened this issue Mar 26, 2019 · 5 comments
Milestone

Comments

@Yona-Appletree
Copy link

Very similar issue to #1805, but when a property name is specified and MapperFeature.USE_GETTERS_AS_SETTERS is enabled:

static class Foo {
    @JsonProperty(value = "list", access = JsonProperty.Access.READ_ONLY)
    List<Long> getList() {
        return Collections.unmodifiableList(Arrays.asList());
    }
}

Fails with com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.UnsupportedOperationException) (through reference chain: com.fasterxml.jackson.databind.deser.ReadOnlyDeserWithNameTest$Foo["list"]->java.util.Collections$UnmodifiableRandomAccessList[0])

Here's the test:

private final ObjectMapper MAPPER = jsonMapperBuilder().configure(MapperFeature.USE_GETTERS_AS_SETTERS, true).build();

public void testReadOnly() throws Exception
{
    String payload = "{\"list\":[1,2,3,4]}";
    Foo foo = MAPPER.readValue(payload, Foo.class);
    assertTrue("List should be empty", foo.getList().isEmpty());
}
@cowtowncoder cowtowncoder added 2.10 and removed 2.10 labels Mar 26, 2019
@cowtowncoder
Copy link
Member

Thank you for reporting this. I hope to have a look relatively soon.

Yona-Appletree pushed a commit to Yona-Appletree/jackson-databind that referenced this issue Mar 26, 2019
…MapperFeature.USE_GETTERS_AS_SETTERS and renaming properties
@Yona-Appletree
Copy link
Author

I went ahead and did my best at fixing this myself and put in a new test and pull request. I'm sure it's not quite up-to-par, but hopefully it can help you get started.

@cowtowncoder cowtowncoder added 2.10 and removed 2.9 labels May 8, 2019
@cowtowncoder
Copy link
Member

Relatively soon was not to happen, but issue is on W-I-P/TODO list at https://github.com/FasterXML/jackson-future-ideas/wiki/Jackson-Work-in-Progress
(fwtw)

@cowtowncoder cowtowncoder added 2.11 and removed 2.10 labels Mar 26, 2020
cowtowncoder added a commit that referenced this issue Apr 2, 2020
@cowtowncoder
Copy link
Member

Added (failing) unit test from #2284, to make it easier to solve this, whether by using (parts of) PR or not.

@cowtowncoder
Copy link
Member

I think I managed to fix this along with #2118 and #2719, for 2.12.0 (fix in 2.12 branch)

@cowtowncoder cowtowncoder changed the title JsonProperty.Access.READ_ONLY fails with collections when a property name is specified JsonProperty.Access.READ_ONLY fails with collections when a property name is specified May 17, 2020
cowtowncoder added a commit that referenced this issue May 17, 2020
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