Description
See the following test:
package org.apache.johnzon.jsonb.polymorphism; import jakarta.json.bind.annotation.JsonbSubtype; import jakarta.json.bind.annotation.JsonbTypeInfo; import org.apache.johnzon.jsonb.test.JsonbRule; import org.junit.Rule; import org.junit.Test; import static org.junit.Assert.assertEquals; public class JsonbNestedPolymorphismTest { @Rule public JsonbRule jsonb = new JsonbRule(); @Test public void test() { Wrapper wrapper = new Wrapper(); wrapper.something = new ConcreteSomething(); assertEquals("{\"something\":{\"@type\":\"concrete\",\"value\":\"asdf\"}}", jsonb.toJson(wrapper)); } @JsonbTypeInfo({ @JsonbSubtype(alias = "concrete", type = ConcreteSomething.class) }) public static class AbstractSomething { } public static class ConcreteSomething extends AbstractSomething { public String value = "asdf"; } public static class Wrapper { public AbstractSomething something; } }
Test result:
org.junit.ComparisonFailure: Expected :{"something":{"@type":"concrete","value":"asdf"}} Actual :{"something":{"value":"asdf"}}