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

JSON-B transient and property annotation collide unexpectedly #444

Closed
aguibert opened this issue Aug 25, 2020 · 3 comments · Fixed by #493
Closed

JSON-B transient and property annotation collide unexpectedly #444

aguibert opened this issue Aug 25, 2020 · 3 comments · Fixed by #493
Assignees
Labels
bug Something isn't working right

Comments

@aguibert
Copy link
Member

Originally raised by @sdaschner in these issues:
OpenLiberty: OpenLiberty/open-liberty#13640
Quarkus: quarkusio/quarkus#11594

Describe the bug
When mapping a class via JSON-B, and annotating fields as follows, the result throws an error because of mismatching types:

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:

[ERROR   ] Unable to serialize property 'order' from com.sebastian_daschner.openliberty.Coffee
[ERROR   ] Generating incomplete JSON
[ERROR   ] Problem with writing the data, class com.sebastian_daschner.openliberty.Coffee, ContentType: application/json

If both properties order and orderLink have the same type, it works as expected (i.e. orderLink is serialized as "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;
    }

}

Response:

{"order":"http://localhost/"}

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

To Reproduce
See code snippets in description

Expected behavior
Original code should deserialize into the expected JSON of:

{"order":"http://localhost/"}

instead of throwing an error

@hbelmiro
Copy link

@aguibert I can try to fix this.

@aguibert
Copy link
Member Author

great, thanks @hbelmiro!

@hbelmiro
Copy link

@aguibert the problem is not happening in current version. It may have already been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working right
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants