JAXB - unmarshalled fields are null

前端 未结 3 1420
忘掉有多难
忘掉有多难 2021-01-12 02:58

We are unmarshalling a response from http://xmlgw.companieshouse.gov.uk/. This is the text sent to the marshall:



        
相关标签:
3条回答
  • 2021-01-12 03:26

    I figured out the correct answer thanks to @Blaise Doughan. After looking at the package namespace qualification I found that it was pointing to:

    "http://xmlgw.companieshouse.gov.uk/v1-0"
    

    and it should have been pointing to:

    "http://xmlgw.companieshouse.gov.uk/v1-0/schema"
    

    Not sure how that got misplaced.

    0 讨论(0)
  • 2021-01-12 03:49

    You need to use a package level @XmlSchema annotation to specify the namespace qualification for your model.

    @XmlSchema(
        namespace = "http://xmlgw.companieshouse.gov.uk/v1-0/schema",
        elementFormDefault = XmlNsForm.QUALIFIED)
    package example;
    
    import javax.xml.bind.annotation.XmlNsForm;
    import javax.xml.bind.annotation.XmlSchema;
    

    This this specified you do not require to specify the namespace URI on the @XmlRootElement and @XmlType on your NameSearch class.

    For More Information

    • http://blog.bdoughan.com/2010/08/jaxb-namespaces.html

    The unmarshaling is done from the first Node extracted from a larger Document, inside an any list of items.

    Make sure the DOM parer used to create the nodes is namespace aware.

    documentBuilderFactory.setNamespaceAware(true);
    
    0 讨论(0)
  • 2021-01-12 03:52

    I solved this by making elementFormDefault="unqualified" in the xsd before generating stubs, else make the change manually in package-info.java

    0 讨论(0)
提交回复
热议问题