Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-1674

JAXB unmarshalling cannot be configured to use the ObjectFactory

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.1, 2.0.7
    • Fix Version/s: 2.1.2
    • Component/s: None
    • Labels:
      None

      Description

      JAXB requires to explicitly configure the Unmarshaller to use the ObjectFactory using setProperty - it will otherwise use reflection (newInstance). An example:

      package test;

      @XmlRootElement
      @XmlType(name = "data")
      public class Data {
      }

      public class ExtendedData extends Data {
      }

      @XmlRegistry
      public class ObjectFactory {
      public Data createData()

      { return new ExtendedData(); }

      }

      public class Test {

      public static void main(String[] args) throws Exception

      { JAXBContext context = JAXBContext.newInstance(Test.class.getPackage().getName()); Unmarshaller u1 = context.createUnmarshaller(); String xml = "<?xml version=\"1.0\"?><data/>"; System.out.println(u1.unmarshal(new StringReader(xml)).getClass().getName()); Unmarshaller u2 = context.createUnmarshaller(); u2.setProperty(com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.FACTORY, new ObjectFactory()); System.out.println(u2.unmarshal(new StringReader(xml)).getClass().getName()); }

      }

      Output:
      test.Data
      test.ExtendedData

      To allow setting the above property JAXBDataBinding, JAXBEncoderDecoder and DataReaderImpl would require "unmarshallerProperties" (in line with existing marshallerProperties for the DataWriterImpl).

        Attachments

          Activity

            People

            • Assignee:
              dkulp Daniel Kulp
              Reporter:
              benneke Andreas Benneke
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: