jaxb
  1. jaxb
  2. JAXB-964

JAXB unmarshalling failing when whitespace is present around token enumerations

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 2.2.7
    • Fix Version/s: None
    • Component/s: runtime, xjc
    • Labels:
      None
    • Environment:

      JDK 1.7.0_21, Ubuntu 12.04.2

      Description

      SO post on the subject: http://stackoverflow.com/questions/17114304/jaxb-unmarshalling-not-tolerating-whitespace-around-token-enumerations

      Here's the code that demonstrates the issue, for completeness purposes:

      A.xsd

      <xs:schema targetNamespace="foo://a"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns="foo://a">

      <xs:element name="type" type="Type"/>

      <xs:simpleType name="Type">
      <xs:restriction base="xs:token">
      <xs:enumeration value="Archive"/>
      <xs:enumeration value="Organisation"/>
      </xs:restriction>
      </xs:simpleType>

      </xs:schema>

      a.xml

      <a:type xmlns:a="foo://a" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="foo://a A.xsd"
      >Organisation </a:type>

      (notice the space after the 'Organisation')

      unmarshalling code that fails

      import java.io.*;
      import javax.xml.XMLConstants;
      import javax.xml.bind.*;
      import javax.xml.validation.Validator;
      import javax.xml.validation.SchemaFactory;
      import javax.xml.validation.Schema;

      import javax.xml.transform.Source;
      import javax.xml.transform.stream.StreamSource;

      import a.*;

      public class FooMain {

      public static void main(String args[]) throws Exception {
      SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
      JAXBContext payloadContext = JAXBContext.newInstance("a");
      Unmarshaller unmarshaller = payloadContext.createUnmarshaller();
      unmarshaller.setSchema(schemaFactory.newSchema(new Source[]

      {new StreamSource(new FileInputStream(new File("A.xsd")))}

      ));
      unmarshaller.setAdapter(new StringTrimAdapter());
      JAXBElement<?> oUnmarshalled = (JAXBElement<?>) unmarshaller.unmarshal(new File("a.xml"));
      Object o = oUnmarshalled.getValue();
      System.out.println("o==null? "+(o==null?"YES":"NO"));
      System.out.println("the type of object is: "+o.getClass().getName()); // NPE here
      }
      }

        Activity

          People

          • Assignee:
            Iaroslav Savytskyi
            Reporter:
            m_perdikeas
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: