jaxb
  1. jaxb
  2. JAXB-877

Parameter JAXBRIContext.IMPROVED_XSI_TYPE_HANDLING does not work with ArrayElementLeafProp

    Details

    • Type: Bug Bug
    • Status: In Progress
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.2.4
    • Fix Version/s: None
    • Component/s: runtime
    • Labels:
      None
    • Environment:

      Windows 7, SpringSource Tool Suite

      Description

      I enbaled the parameter JAXBRIContext.IMPROVED_XSI_TYPE_HANDLING and all my SingleElementLeadProperties get the correct xsi:type set.
      The ArrayElementLeafProperties do not get the xsi:type although the parameter is set to true.

        Activity

        Hide
        Iaroslav Savytskyi added a comment -

        Hi, finally I have time to go through bugs.

        Thank you for reporting... I would ask you to provide some simple testCase. It will help to quickly localize and fix the problem.

        Thanks.

        Yaroslav

        Show
        Iaroslav Savytskyi added a comment - Hi, finally I have time to go through bugs. Thank you for reporting... I would ask you to provide some simple testCase. It will help to quickly localize and fix the problem. Thanks. – Yaroslav
        Hide
        Martin Grebac added a comment -

        Hi, mark the issue as incomplete if you're missing testcase.

        Show
        Martin Grebac added a comment - Hi, mark the issue as incomplete if you're missing testcase.
        Hide
        goran.marjanovic added a comment - - edited

        Hi...

        well, I hope I could remember a testcase. Hier is the XSD:

        <?xml version="1.0" encoding="utf-8" ?>
        <xsd:schema xmlns:mime="http://www.w3.org/2005/05/xmlmime" xmlns="http://namespace" attributeFormDefault="qualified" elementFormDefault="qualified"
        	targetNamespace="http://namespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        	<xsd:complexType name="SomeType" abstract="true">
        		<xsd:simpleContent>
        			<xsd:extension base="xsd:string" />
        		</xsd:simpleContent>
        	</xsd:complexType>
        	<xsd:complexType name="SomeTypeBase">
        		<xsd:simpleContent>
        			<xsd:extension base="SomeType">
        				<xsd:attribute name="LastName" type="xsd:string"></xsd:attribute>
        				<xsd:attribute name="FirstName" type="xsd:string"></xsd:attribute>
        			</xsd:extension>
        		</xsd:simpleContent>
        	</xsd:complexType>
        	<xsd:complexType name="AnotherType" abstract="true">
        		<xsd:simpleContent>
        			<xsd:extension base="xsd:string" />
        		</xsd:simpleContent>
        	</xsd:complexType>
        	<xsd:complexType name="AnotherTypeBase">
        		<xsd:simpleContent>
        			<xsd:extension base="AnotherType">
        				<xsd:attribute name="Street" type="xsd:string"></xsd:attribute>
        				<xsd:attribute name="City" type="xsd:string"></xsd:attribute>
        			</xsd:extension>
        		</xsd:simpleContent>
        	</xsd:complexType>
        	<xsd:element name="SomeElement">
        		<xsd:complexType>
        			<xsd:sequence>
        				<xsd:element name="SType" type="SomeType" minOccurs="0" maxOccurs="unbounded" />
        				<xsd:element name="AType" type="AnotherType" minOccurs="1" maxOccurs="1" />
        			</xsd:sequence>
        		</xsd:complexType>
        	</xsd:element>
        </xsd:schema>
        

        This is my Testcode:

        MyTest.java
        package de.test.bin;
        
        import java.util.HashMap;
        
        import javax.xml.bind.JAXBContext;
        import javax.xml.bind.JAXBException;
        import javax.xml.bind.Marshaller;
        
        import com.sun.xml.bind.api.JAXBRIContext;
        import com.sun.xml.bind.v2.ContextFactory;
        
        import namespace.AnotherType;
        import namespace.AnotherTypeBase;
        import namespace.SomeElement;
        import namespace.SomeType;
        import namespace.SomeTypeBase;
        
        public class MyTest {
        
        	public static void main(String[] args) {
        		try {
        
        			HashMap map = new HashMap();
        			map.put(JAXBRIContext.IMPROVED_XSI_TYPE_HANDLING, Boolean.FALSE);
        
        			JAXBRIContext jaxbContext = (JAXBRIContext) ContextFactory.createContext("namespace", Thread
        					.currentThread().getContextClassLoader(), map);
        
        			SomeElement someElement = new SomeElement();
        
        			SomeType a = new SomeTypeBase();
        			a.setValue("Foo");
        
        			SomeType b = new SomeTypeBase();
        			b.setValue("Bar");
        
        			someElement.getSType().add(a);
        			someElement.getSType().add(b);
        
        			AnotherType c = new AnotherTypeBase();
        			c.setValue("anothetValue");
        
        			someElement.setAType(c);
        
        			Marshaller m = jaxbContext.createMarshaller();
        			m.setProperty("jaxb.formatted.output", Boolean.TRUE);
        			m.marshal(someElement, System.err);
        		}
        		catch (JAXBException e) {
        			// TODO Auto-generated catch block
        			e.printStackTrace();
        		}
        
        	}
        }
        

        If JAXBRIContext.IMPROVED_XSI_TYPE_HANDLING is set to FALSE I got the following output:

         
        <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
        <ns1:SomeElement xmlns:ns1="http://namespace">
            <ns1:SType>Foo</ns1:SType>
            <ns1:SType>Bar</ns1:SType>
            <ns1:AType>anothetValue</ns1:AType>
        </ns1:SomeElement>
        

        If JAXBRIContext.IMPROVED_XSI_TYPE_HANDLING is set to TRUE I got the following output:

        <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
        <ns1:SomeElement xmlns:ns1="http://namespace">
            <ns1:SType>Foo</ns1:SType>
            <ns1:SType>Bar</ns1:SType>
            <ns1:AType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns1:AnotherTypeBase">anothetValue</ns1:AType>
        </ns1:SomeElement>
        

        The element AType gets the type-attribute if the property is set to true. But the element SType still has no type-attribute.

        I hope this testcase can help you.

        Best regards
        Goran

        Show
        goran.marjanovic added a comment - - edited Hi... well, I hope I could remember a testcase. Hier is the XSD: <?xml version= "1.0" encoding= "utf-8" ?> <xsd:schema xmlns:mime = "http://www.w3.org/2005/05/xmlmime" xmlns= "http://namespace" attributeFormDefault= "qualified" elementFormDefault= "qualified" targetNamespace= "http://namespace" xmlns:xsd = "http://www.w3.org/2001/XMLSchema" > <xsd:complexType name= "SomeType" abstract= "true" > <xsd:simpleContent> <xsd:extension base= "xsd:string" /> </xsd:simpleContent> </xsd:complexType> <xsd:complexType name= "SomeTypeBase" > <xsd:simpleContent> <xsd:extension base= "SomeType" > <xsd:attribute name= "LastName" type= "xsd:string" > </xsd:attribute> <xsd:attribute name= "FirstName" type= "xsd:string" > </xsd:attribute> </xsd:extension> </xsd:simpleContent> </xsd:complexType> <xsd:complexType name= "AnotherType" abstract= "true" > <xsd:simpleContent> <xsd:extension base= "xsd:string" /> </xsd:simpleContent> </xsd:complexType> <xsd:complexType name= "AnotherTypeBase" > <xsd:simpleContent> <xsd:extension base= "AnotherType" > <xsd:attribute name= "Street" type= "xsd:string" > </xsd:attribute> <xsd:attribute name= "City" type= "xsd:string" > </xsd:attribute> </xsd:extension> </xsd:simpleContent> </xsd:complexType> <xsd:element name= "SomeElement" > <xsd:complexType> <xsd:sequence> <xsd:element name= "SType" type= "SomeType" minOccurs= "0" maxOccurs= "unbounded" /> <xsd:element name= "AType" type= "AnotherType" minOccurs= "1" maxOccurs= "1" /> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> This is my Testcode: MyTest.java package de.test.bin; import java.util.HashMap; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import com.sun.xml.bind.api.JAXBRIContext; import com.sun.xml.bind.v2.ContextFactory; import namespace.AnotherType; import namespace.AnotherTypeBase; import namespace.SomeElement; import namespace.SomeType; import namespace.SomeTypeBase; public class MyTest { public static void main( String [] args) { try { HashMap map = new HashMap(); map.put(JAXBRIContext.IMPROVED_XSI_TYPE_HANDLING, Boolean .FALSE); JAXBRIContext jaxbContext = (JAXBRIContext) ContextFactory.createContext( "namespace" , Thread .currentThread().getContextClassLoader(), map); SomeElement someElement = new SomeElement(); SomeType a = new SomeTypeBase(); a.setValue( "Foo" ); SomeType b = new SomeTypeBase(); b.setValue( "Bar" ); someElement.getSType().add(a); someElement.getSType().add(b); AnotherType c = new AnotherTypeBase(); c.setValue( "anothetValue" ); someElement.setAType(c); Marshaller m = jaxbContext.createMarshaller(); m.setProperty( "jaxb.formatted.output" , Boolean .TRUE); m.marshal(someElement, System .err); } catch (JAXBException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } If JAXBRIContext.IMPROVED_XSI_TYPE_HANDLING is set to FALSE I got the following output: <?xml version= "1.0" encoding= "UTF-8" standalone= "yes" ?> <ns1:SomeElement xmlns:ns1 = "http://namespace" > <ns1:SType> Foo </ns1:SType> <ns1:SType> Bar </ns1:SType> <ns1:AType> anothetValue </ns1:AType> </ns1:SomeElement> If JAXBRIContext.IMPROVED_XSI_TYPE_HANDLING is set to TRUE I got the following output: <?xml version= "1.0" encoding= "UTF-8" standalone= "yes" ?> <ns1:SomeElement xmlns:ns1 = "http://namespace" > <ns1:SType> Foo </ns1:SType> <ns1:SType> Bar </ns1:SType> <ns1:AType xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:type= "ns1:AnotherTypeBase" > anothetValue </ns1:AType> </ns1:SomeElement> The element AType gets the type-attribute if the property is set to true. But the element SType still has no type-attribute. I hope this testcase can help you. Best regards Goran

          People

          • Assignee:
            Iaroslav Savytskyi
            Reporter:
            goran.marjanovic
          • Votes:
            4 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated: