JAXB with namespace unmarshalling (using Jersey from REST service)

后端 未结 2 1633
天涯浪人
天涯浪人 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条回答
  •  说谎
    说谎 (楼主)
    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.

提交回复
热议问题