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

JsonBindingProvider.writeTo() Failed to Process Polymorphic Object #5125

Open
arieki opened this issue Aug 11, 2022 · 5 comments
Open

JsonBindingProvider.writeTo() Failed to Process Polymorphic Object #5125

arieki opened this issue Aug 11, 2022 · 5 comments

Comments

@arieki
Copy link

arieki commented Aug 11, 2022

this PR #5047 breaks the polymorphic behaviour.
I found a problem when the object is polymorphism, the JSON object won't be written into the entityStream.

When the object is polymorphism it will have a parent class type as genericType value which causes the entityStream is not written correctly which makes the entityStream value = {}.

jsonb.toJson(object, type, writer) will only write the object into entityStream if the object has equal class type with type parameter

@senivam
Copy link
Contributor

senivam commented Aug 11, 2022

thanks for the report! Could you please provide a reproducer?

@arieki
Copy link
Author

arieki commented Aug 15, 2022

thanks for the report! Could you please provide a reproducer?

Sorry for the late response,
I found this issue while running opentracing-tck against Payara 6.

Here is the simple reproducer https://github.com/arieki/jersey-reproducer
you may run it against Payara 6 version 6.2022.1.Alpha4.RC2

@arieki
Copy link
Author

arieki commented Aug 15, 2022

I will submit a PR for the fixing ASAP

@jbescos
Copy link
Member

jbescos commented Sep 5, 2022

Hi @arieki

I am testing this in master and tests are passing. Here is the test:

public class Issue5125Test extends JerseyTest {

    @Override
    protected Application configure() {
        return new ResourceConfig(Resource.class).register(JsonBindingFeature.class);
    }

    @Test
    public void entity() {
        assertEquals("{\"name\":\"this is simple entity\",\"type\":\"simple entity\"}",
                target("/test/entity").request().get(String.class));
    }

    @Test
    public void simpleEntity() {
        assertEquals("{\"name\":\"this is simple entity\",\"type\":\"simple entity\"}",
                target("/test/simpleEntity").request().get(String.class));
    }

    @Path("/test")
    public static class Resource {

        @Path("/entity")
        @GET
        @Produces(MediaType.APPLICATION_JSON)
        public Entity getEntity() {
            SimpleEntity simpleEntity = new SimpleEntity();
            simpleEntity.setName("this is simple entity");
            return simpleEntity;
        }

        @Path("/simpleEntity")
        @GET
        @Produces(MediaType.APPLICATION_JSON)
        public SimpleEntity getSimpleEntity() {
            SimpleEntity simpleEntity = new SimpleEntity();
            simpleEntity.setName("this is simple entity");
            return simpleEntity;
        }
    }

    public static interface Entity {
        String getType();
    }

    public static class SimpleEntity implements Entity {
        private String name;
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        @Override
        public String getType() {
            return "simple entity";
        }
    }
}

@jansupol
Copy link
Contributor

jansupol commented Sep 20, 2022

Glassfish 6.2.5 with Jersey 3.0.8 (and Jackson jackson-module-jakarta-xmlbind-annotations-2.13.3.jar added - required by Jersey Jackson modules), reproduced:

{"name":"this is simple entity","type":"simple entity"}

Either Jersey fixed that, or it's a bug in Payara (Payara builds Jersey from their repository for some reason)

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

4 participants