Quarkus: JSON-B transient and property annotation collide unexpectedly

Created on 25 Aug 2020  路  8Comments  路  Source: quarkusio/quarkus

When mapping a class via JSON-B, and annotating fields as follows, the result either throws an error with type mismatch, or mistakenly serializes the wrong property:

public class Coffee {

    @JsonbTransient
    private Order order;

    @JsonbProperty("order")
    private URI orderLink;

    Coffee() {
        order = new Order();
        orderLink = URI.create("http://localhost/");
    }

    // getters & setters
}

this results in:

Caused by: javax.json.bind.JsonbException: Unable to serialize property 'order' from com.sebastian_daschner.coffee.Coffee
    at org.eclipse.yasson.internal.serializer.ObjectSerializer.serializeInternal(ObjectSerializer.java:71)
    [...]
Caused by: java.lang.ClassCastException: com.sebastian_daschner.coffee.Order incompatible with java.net.URI
    at org.eclipse.yasson.internal.serializer.URITypeSerializer.serialize(URITypeSerializer.java:25)

If both properties order and orderLink have the same type, it serializes the wrong property:

public class Coffee {

    @JsonbTransient
    private URI order;

    @JsonbProperty("order")
    private URI orderLink;

    Coffee() {
        order = URI.create("http://localhost/order");
        orderLink = URI.create("http://localhost/");
    }

    // getters & setters
}
{"order":"http://localhost/order"}

However, if we annotate @JsonbProperty on the setter instead, it works:

public class Coffee {

    @JsonbTransient
    private Order order;

    private URI orderLink;

    // [...]

    @JsonbProperty("order")
    public URI getOrderLink() {
        return orderLink;
    }

}

There seems to be an unexpected type link of the (ignored) property with the default serialized JSON key "order", and the custom name binding.

Tested with Quarkus 1.7.0.Final.

kinbug

All 8 comments

I can take a look at this.

Is it a Quarkus issue or a JSON-B issue? I.e. do you reproduce it with only JSON-B?

@gsmet It is a JSON-B issue. I just reproduced it with only JSON-B.

@gsmet It might be a Yasson issue, yes...

Yeah so better open a Yasson issue.

cc @aguibert

Thanks for the ping, this is indeed a Yasson issue and a duplicate of this OpenLiberty issue I received from Sebastian around the same time:
https://github.com/OpenLiberty/open-liberty/issues/13640

I've transferred this to a yasson issue, and will provide a resolution there. I'll have to review the spec to determine what it says about this scenario, it may be working as intended.

In the meantime, we can leave this item open or close it out, whichever you prefer @gsmet.

Also, @hbelmiro if you are interested in looking into this further that would be much appreciated -- please chime in on the Yasson issue if so.

Thanks @aguibert for taking care!

Yes, I tested that scenario with both runtimes, the effect was slightly different, so wasn't sure if same underlying cause...

Was this page helpful?
0 / 5 - 0 ratings