JAXB with namespace unmarshalling (using Jersey from REST service)

后端 未结 2 1632
天涯浪人
天涯浪人 2021-01-13 22:26

I\'m trying to unmarshal a simple xml document from a public api from Convio. I\'m not getting any compiler errors with the following code, but it won\'t produce a result ei

相关标签:
2条回答
  • You could add a package level annotation (this is done on a class called package-info) and specify elementFormDefault="qualified", then you wouldn't need to qualify each @XmlElement annotation.

    @javax.xml.bind.annotation.XmlSchema(
       namespace="http://convio.com/crm/v1.0".
       elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) 
    package com.convio.crm; 
    

    For more information on JAXB and namespaces see:

    • http://bdoughan.blogspot.com/2010/08/jaxb-namespaces.html
    0 讨论(0)
  • 2021-01-13 23:08

    The namespace is not "inherited" by the fields on the bound class. You need to define the namespace on the fields as well:

    @XmlRootElement(name = "getSingleSignOnTokenResponse", namespace = "http://convio.com/crm/v1.0")
    public class SingleSignOnResponseBean
    {
      @XmlElement(name = "token", namespace = "http://convio.com/crm/v1.0")
      public String token;
      @XmlElement(name = "cons_id", namespace = "http://convio.com/crm/v1.0")
      public int consId;
    }
    

    If you omit them, then the fields go back to the "default" namespace (i.e. no namespace).

    It's mildly irritating, but that's the way it is.

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