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

@JsonUnwrapped conflicts with @JsonAnySetter/@JsonAnyGetter #10

Closed
clanie opened this issue Mar 30, 2013 · 5 comments
Closed

@JsonUnwrapped conflicts with @JsonAnySetter/@JsonAnyGetter #10

clanie opened this issue Mar 30, 2013 · 5 comments

Comments

@clanie
Copy link

clanie commented Mar 30, 2013

I have this class:

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

    @JsonProperty("txid")
    private String txId;

    @JsonProperty("vout")
    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 {

    @JsonUnwrapped
    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
     */
    @JsonAnySetter
    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. 
     */
    @JsonAnyGetter
    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:

{"txid":"280acc1c3611fee83331465c715b0da2d10b65733a688ee2273fdcc7581f149b","vout":0,"scriptPubKey":"76a91426ab1c83e2a8269b7007baf0244151cca4c5e3fd88ac","amount":5.00000000,"confirmations":956}

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:

{"txid":"280acc1c3611fee83331465c715b0da2d10b65733a688ee2273fdcc7581f149b","vout":0,"scriptPubKey":"76a91426ab1c83e2a8269b7007baf0244151cca4c5e3fd88ac","amount":5.00000000,"confirmations":956,"vout":0,"txid":"280acc1c3611fee83331465c715b0da2d10b65733a688ee2273fdcc7581f149b"}

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

@cowtowncoder
Copy link
Member

Not entirely surprised by this, and not sure if it can be fixed. But hope to figure it out, eventually.

For future reference, bugs wrt handling of annotations should go in jackson-databind, since this package only has annotations themselves, and not code handling them.

@zardojunior
Copy link

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

@michalmela
Copy link

For any poor souls who stumbled here looking for answers like I did, see FasterXML/jackson-databind#349

@refacktor
Copy link

This is still broken as of 2.9.9

@cowtowncoder
Copy link
Member

jackson-annotations package only defines annotations and does not implement handling.
So issue would need to go in jackson-databind, and there is

FasterXML/jackson-databind#1811

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

5 participants