Jax-WS - To Remove Empty Tags from Request XML

前端 未结 3 1744
后悔当初
后悔当初 2021-01-03 07:10

I\'m trying to consume a web service exposed by a provider. The Provider has a strict checking at his end that the request xml should not contain tags which don\'t have valu

3条回答
  •  误落风尘
    2021-01-03 08:09

    This is a problem of the XML Serializer that you are using (If you did not do something special it should be JAXB).

    The "null policy" of the serializer should be configurable, but I think is not possible with JAXB. If you use MOXy you can use XmlMarshalNullRepresentation.ABSENT_NODE to do not write the node if it is null. The implementation should be something like this:

    class MyClass {
    
        // ... here are your other attributes
    
        @XmlElement (name = "strIpAddress")
        @XmlNullPolicy(nullRepresentationForXml = XmlMarshalNullRepresentation.ABSENT_NODE)
        String strIpAddress = null;
    
    }
    

    PS: Maybe you need to define also the emptyNodeRepresentsNull param of the @XmlNullPolicy.

    For more information about this subject, please check this question

提交回复
热议问题