Results 1 to 1 of 1
  1. #1
    kmera is offline Member
    Join Date
    Aug 2014
    Posts
    1
    Rep Power
    0

    Default Jaxb inheritance

    I am trying to marshal / unmarshal xml and json using jaxb and jackson.
    I am having issues with parent / child inheritance with my xml annotations.
    Basically I want the parent class to wrap the child class, and then the child class will have the "type" decleration.
    "testResult" is the parent class, "testResultQuantitative" is one of the children.

    My Json object is marshaled appropriately: (sorry if format is incorrect)
    Java Code:
    {"testResult":
         {"type":"testResultQuantitative","result":0.0}
    }
    The Xml object does not have the parent wrapper:
    Java Code:
    <testResultQuantitative>
    	<result>0.0</result>
    </testResultQuantitative>
    Here are the associated classes:
    TestResult class
    Java Code:
    @JsonTypeInfo(use=JsonTypeInfo.Id.NAME, 
        include=JsonTypeInfo.As.PROPERTY, 
        property="type"
        )
    @JsonSubTypes({
        @JsonSubTypes.Type(value=TestResultQualitative.class, name="testResultQualitative"),
        @JsonSubTypes.Type(value=TestResultQuantitative.class, name="testResultQuantitative")
    })
    @XmlRootElement(name="testResult")
    @XmlSeeAlso({TestResultQualitative.class, TestResultQuantitative.class})
    public abstract class TestResult {
       ...
    }
    TestResultQuantitative class
    Java Code:
    @JsonTypeName("testResultQuantitative")
    @XmlType(name="testResultQuantitative")
    public class TestResultQuantitative extends TestResult {
       ...
    }
    EDIT:
    To be more clear on the formatting I am looking for:
    Java Code:
    <testResult xsi:type="testResultQuantitative">
            <result>0.0</result>
    </testResult>
    Last edited by kmera; 08-25-2014 at 07:24 PM.

Similar Threads

  1. Jaxb
    By unknownuser in forum Advanced Java
    Replies: 2
    Last Post: 08-14-2013, 11:55 AM
  2. JAXB type help!!!
    By mafyou in forum XML
    Replies: 1
    Last Post: 04-23-2012, 11:53 AM
  3. JAXB Unmarshalling
    By milan.nosal in forum XML
    Replies: 0
    Last Post: 09-01-2010, 03:15 PM
  4. Jaxb
    By Paul Richards in forum XML
    Replies: 1
    Last Post: 08-03-2009, 10:56 PM
  5. JAXB Unmarshalling
    By prateek in forum XML
    Replies: 0
    Last Post: 07-10-2008, 07:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •