JAXB - unmarshalled fields are null

前端 未结 3 1443
忘掉有多难
忘掉有多难 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条回答
  •  梦毁少年i
    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);
    

提交回复
热议问题