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

How to parse (nested) interfaces? How to map interfaces to concrete implementation? #65

Open
jansupol opened this issue Oct 22, 2017 · 5 comments

Comments

@jansupol
Copy link
Owner

I have a interface model like:

public interface Customer {

    String getName();
    Address getAddress();
}

public interface Address {

    String getStreet();
    String getCity();
}

For each interface there is a single implementation.
Important to note that the model contains nested properties/types using (again) interfaces.

How can this be parsed?

JsonbConfig config = new JsonbConfig()
// TODO: what configuration to add to map interfaces to concrete implementations?
Jsonb jsonb = JsonbBuilder.create(config)
jsonb.fromJson(json, Customer.class);

Above gives exception: javax.json.bind.JsonbException: interface com.acme.Customer not instantiable

Note: I cannot change the interfaces nor the concrete implementations as these are provided.

@jansupol
Copy link
Owner Author

@bravehorsie Commented
There is already a pull request for this in the Yasson RI.
eclipse-ee4j/yasson#64
@m0mus Can we move annotation and JsonbConfig in the above pull request to the spec for next release? Looks like a handy feauture.

@jansupol
Copy link
Owner Author

@marceloverdijk Commented
Can that solution be used without an @annotation?
In my case I cannot change the classes itself.

@jansupol
Copy link
Owner Author

@bravehorsie Commented
You can also add mapping with JsonbConfig see https://github.com/eclipse/yasson/pull/64/files#diff-42990ea8091951c02b2166a51a23f6a6 second test method.
In your case it is also enough to call:
Customer customer = jsonb.fromJson(json, CustomerImpl.class);

@jansupol
Copy link
Owner Author

@marceloverdijk Commented
Thanks! Looking forward to see this incorporated in the jsonb spec.

@jansupol
Copy link
Owner Author

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

1 participant