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

Support deserialization of array field using elementwise addition method #1560

Closed
nmatt opened this issue Mar 16, 2017 · 3 comments
Closed

Comments

@nmatt
Copy link

nmatt commented Mar 16, 2017

I have a third-party class for which I want to write a mixin. The class has collection-valued properties for which it has regular getters, but no collection-valued setters. Instead, it has "add" methods to add the collection elements one by one. E.g.:

    public Set<Foo> getFoos();
    public void addFoo(Foo foo);

It would be nice if some variant of @JsonProperty could be used on addFoo(Foo) to tell Jackson that, when deserializing foos, it should add the elements one by one using addFoo(Foo).

@nmatt nmatt changed the title Support deserialization of array field usin elementwise addition method Support deserialization of array field using elementwise addition method Mar 16, 2017
@cowtowncoder
Copy link
Member

Ok, that is a possible addition.

But just in case, I'll mention that feature #1399 being added in 2.9 (2.9.0.pr1 is out) allows specifying properties to use "merge", like

    @JsonMerge(OptBoolean.TRUE)
    public Set<Foo> getFoos() { }

in which case add() method will be used to append entries to existing value, instead of default overwriting.
This works for different kinds of types; for POJOs it would avoid new instance construction, similarly for Map.

@nmatt
Copy link
Author

nmatt commented Mar 17, 2017

Thanks, #1399 indeed is an alternative when the getter returns a modifiable reference to the internal state.

@cowtowncoder
Copy link
Member

At this point, I have no plans to implement this feature, so closing.

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