Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@JsonUnwrapped conflicts with @JsonAnySetter/@JsonAnyGetter

See original GitHub issue

I have this class:

@RooJavaBean(settersByDefault = false)
@JsonPropertyOrder({"txid", "vout"})
public class TransactionOutputRef extends BaseClass {

    private String txId;

    private Integer vout;

     * Full constructor.
     * @param txId - transaction id.
     * @param vout - output number.
    public TransactionOutputRef(@JsonProperty("txid") String txId, @JsonProperty("vout") Integer vout) {
        this.txId = txId;
        this.vout = vout;


Which is used as an @JsonUnwrapped property in this class:

@RooJavaBean(settersByDefault = false)
public class ListUnspentResult extends JsonExtra {

    private TransactionOutputRef txRef;

    private String scriptPubKey;
    private BigDecimal amount;
    private Integer confirmations;

    private Map<String, Object> otherFields = newHashMap();

     * Sets name and value of other (unknown) JSON fields.
     * @param field
     * @param value
    public void set(String field, Object value)  {
        otherFields.put(field, value);

     * Gets names and values of all other (unknown) JSON fields.
     * @return Names of other fields available. 
    public Map<String, Object> getOtherFields() {
        return Collections.unmodifiableMap(otherFields);


As you can see the class also has @JsonAnyGetter and @JsonAnySetter methods to collect other fields.

Now, if i deserialize this:


I get an ListUnspentResult object, where txid and vout are stored in both the txRef property annotated with @JsonUnwrapped AND in the otherFields map, and when I serialize it back to json, I get this:


where txid and vout (the properties of TransactionOutputRef ) are included twice.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

michalmelacommented, Aug 4, 2017

For any poor souls who stumbled here looking for answers like I did, see

zardojuniorcommented, Jul 25, 2017

Hi @clanie Im having the same problem. Did you solve yours? How?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why I'm not able to unwrap and serialize a Java map using the ...
@JsonUnwrapped doesn't work for maps, only for proper POJOs with getters and setters. For maps, You should use @JsonAnyGetter and @JsonAnySetter (available ...
Read more >
Jackson Annotation Examples - Baeldung
The @JsonAnyGetter annotation allows for the flexibility of using a Map field ... First, we'll use @JsonAnySetter to deserialize the entity ...
Read more >
Guide to Jackson Annotations | Novixys Software Dev Blog
Introduction. Jackson provides a number of annotations which help tweak various facets of JSON serialization and deserialization.
Read more >
Аннотации Jackson |
С аннотацией @JsonAnyGetter Jackson сериализует атрибуты key-value как ... Применим @JsonAnySetter для десериализации объектаExtendableBean:.
Read more >
Jackson Annotation Examples - 码农在路上 - 博客园
The @JsonAnyGetter annotation allows the flexibility of using a Map field as ... Let's see how this works – we'll use @JsonAnySetter to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found