On Wed, Jul 10, 2019 at 4:55 PM Raffaele Gambelli <[email protected]> wrote:
>
> Hi all,
>
> I'm experiencing some jon fields duplication problems using @JsonAnyGetter 
> annotation.
>
> If I have a class with a name attribute and its getter and a map annotated 
> with @JsonAnyGetter containing an entry having "name" as key, resulting json 
> has two fields "name".
>
> Consider this simple and incomplete snippet:
>
> public class JsonObject {
>
>     private String name;
>     private final Map<String, Object> map = new HashMap<>();
>
>     public String getName() {
>         return (String) get("name");
>     }
>
>     @JsonAnyGetter
>     public Map<String, Object> get() {
>         return map;
>     }
>
>     @JsonAnySetter
>     public Object put(String key, Object value) {
>         return map.put(key, value);
>     }
> }
>
> Is there a way to ignore my getName() method or is there a way to remove the 
> duplication?
> Please consider that my example is very simple, my real case is more complex, 
> I have some classes which extend a class containing the map, children classes 
> contain specific getter and setter (e.g. getName() setName()) which work 
> directly with the map attribute present in parent class.
>
> Thank you very much, best regards
> Inserisci qui il codice...

No, unfortunately there is currently no way to instruct Jackson to
ignore entries from `Map` returned by `@JsonAnyGetter` annotated
method.

But maybe it is worth filing a feature request issue at Github? This
sounds like a reasonable feature request.

-+ Tatu +-

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/CAL4a10jdoPLPbQfA-_%3D3jY8R6Fgw0FCP0qr%2BD%2BF0krGp7MUA5A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to