jaxb-ri icon indicating copy to clipboard operation
jaxb-ri copied to clipboard

fixed attribute value not used when using restriction inheritance

Open Tomas-Kraus opened this issue 18 years ago • 6 comments

If a complex type with one attribute is inherited by restriction and in the inheriting element we define a fixed value for that attribute, the JAXB bean returns null for it except we set it explicitly.

In my eyes this is a bug, as the JAXB bean should always return the fixed value.

I've created some test files, but it seems like I can't upload them, so I just paste my files in here:


– XSD file ----------------------------------------------

<xsd:schema xmlns:core="http://paybox.net/xml/schema/core" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://paybox.net/xml/schema/core" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="2.0"> xs:annotation xs:appinfo jxb:schemaBindings <jxb:package name="net.paybox.mobiliser.jaxb" /> </jxb:schemaBindings> </xs:appinfo> </xs:annotation>

<xsd:simpleType name="IdentifierType"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="id" /> <xsd:enumeration value="imei" /> <xsd:enumeration value="msisdn" /> </xsd:restriction> </xsd:simpleType>

<xsd:complexType name="Identifier"> xsd:simpleContent <xsd:extension base="xsd:string"> <xsd:attribute name="type" use="optional" type="core:IdentifierType" /> </xsd:extension> </xsd:simpleContent> </xsd:complexType>

<xsd:complexType name="IdIdentifier"> xsd:simpleContent <xsd:restriction base="core:Identifier"> <xsd:pattern value="\d

{1,12}

" /> <xsd:attribute fixed="id" name="type" type="core:IdentifierType" /> </xsd:restriction> </xsd:simpleContent> </xsd:complexType>

<xsd:complexType name="BaseCustomer"> xsd:sequence <xsd:element name="Identification" type="core:Identifier" /> </xsd:sequence> </xsd:complexType>

<xsd:complexType name="Merchant"> xsd:complexContent <xsd:restriction base="core:BaseCustomer"> xsd:sequence <xsd:element name="Identification" type="core:IdIdentifier"> </xsd:element> </xsd:sequence> </xsd:restriction> </xsd:complexContent> </xsd:complexType>

<xsd:element name="Root"> xsd:complexType xsd:sequence <xsd:element name="Recipient" type="core:BaseCustomer" /> <xsd:element name="Seller" type="core:Merchant" /> </xsd:sequence> </xsd:complexType> </xsd:element>

</xsd:schema>


– XML file ----------------------------------------------

<core:Root xmlns:core="http://paybox.net/xml/schema/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://paybox.net/xml/schema/core bugReport.xsd "> <Recipient> <Identification type="msisdn">+1781807531</Identification> </Recipient> <Seller> <Identification>123456789012</Identification> </Seller> </core:Root>


– JUnit -------------------------------------------------

import java.io.File;

import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.validation.SchemaFactory;

import net.paybox.mobiliser.jaxb.Root;

import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.xml.sax.SAXException;

public class TestJaxb {

private static Unmarshaller unMarshal;

@BeforeClass public static void init() throws JAXBException, SAXException

{ unMarshal = JAXBContext.newInstance("net.paybox.mobiliser.jaxb") .createUnmarshaller(); unMarshal.setSchema(SchemaFactory.newInstance( "http://www.w3.org/2001/XMLSchema").newSchema( new File("bugReport.xsd"))); }

@Test public void parse() throws JAXBException

{ Root root = (Root) unMarshal.unmarshal(new File("bugReport.xml")); Assert.assertNotNull(root.getRecipient().getIdentification().getType()); Assert.assertNotNull(root.getSeller().getIdentification().getType()); }

}

Environment

Operating System: All Platform: All

Affected Versions

[2.0.3]

Tomas-Kraus avatar Oct 26 '06 13:10 Tomas-Kraus

  • Issue Imported From: https://github.com/javaee/jaxb-v2/issues/270
  • Original Issue Raised By:@glassfishrobot
  • Original Issue Assigned To: @glassfishrobot

Tomas-Kraus avatar Sep 21 '18 14:09 Tomas-Kraus

@glassfishrobot Commented Reported by sebastiankirsch

Tomas-Kraus avatar Oct 26 '06 13:10 Tomas-Kraus

@glassfishrobot Commented kohsuke said: I believe the current behavior is in accordance with the spec.

I agree with you that the behavior you are describing would make a lot of sense, and such behavior is certainly worth considering for vendor extensions. It's just that there are so many ways to restrict a content model, and have the compiler recognize those correctly would be a non-trivial work.

Tomas-Kraus avatar Nov 13 '06 14:11 Tomas-Kraus

@glassfishrobot Commented kohsuke said: Since this is not a "bug" in the sense of spec violation, I'm changing it to ENHANCEMENT.

Tomas-Kraus avatar Nov 13 '06 14:11 Tomas-Kraus

@glassfishrobot Commented Was assigned to jaxb-issues

Tomas-Kraus avatar Oct 26 '06 13:10 Tomas-Kraus

@glassfishrobot Commented This issue was imported from java.net JIRA JAXB-270

Tomas-Kraus avatar Apr 24 '17 11:04 Tomas-Kraus