Uploaded image for project: 'Johnzon'
  1. Johnzon
  2. JOHNZON-401

Polymorphism attributes not serialized in nested objects

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.0.0
    • 2.0.1
    • JSON-B
    • None

    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"}}
      

      Attachments

        Activity

          People

            markus-jung Markus Jung
            markus-jung Markus Jung
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h