Markus Jung created JOHNZON-401:
-----------------------------------
Summary: Polymorphism attributes not serialized in nested objects
Key: JOHNZON-401
URL: https://issues.apache.org/jira/browse/JOHNZON-401
Project: Johnzon
Issue Type: Bug
Components: JSON-B
Affects Versions: 2.0.0
Reporter: Markus Jung
See the following test:
{code:java}
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;
}
}
{code}
Test result:
{code:java}
org.junit.ComparisonFailure:
Expected :{"something":{"@type":"concrete","value":"asdf"}}
Actual :{"something":{"value":"asdf"}}
{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)