0

Consider the following code with JAXB binding,

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class SomeRequest {

    @XmlElements(value={@XmlElement(name="objOne", type="ObjectOne.class"),
    @XmlElement(name="objTwo", type="ObjectTwo.class")})
    private MyObject obj;

}

When I get a request similar to this,

<request>
    <objectOne>
        <!-- Some Data -->
    </objectOne>
    <objectTwo>
        <!-- Some data -->
    </objectTwo>
</request>

Both the values are unmarshalled and processed, but only the last value of objectTwo remains.

I want to avoid this some way, by throwing an exception when both are sent in the request.

Also, I am looking for a way to solve it programmatically, without using wsdl schema validation..

I have tried to use, JAXB XmlAdapter after looking at the following question,

Confused as how to use JAXB XML Adapter for my requirement but there is no way to compare if the object has already a value and throw a soap fault.

I also couldn't think of a way of solving it using Unmarshaller, from the oracle jaxb docs

If you could recommend a solution using some kind of Interceptor or extending some JAXB class and validate and throw an exception, it would be great.

The web service implementation is done using apache cxf on jboss, if it helps. CXF Interceptors are also an option but I would take that only if there is no JAXB related solution.

Community
  • 1
  • 1
BST
  • 531
  • 5
  • 18
  • You expect only one value of `objTwo`, so where's the problem? – Smutje Feb 26 '14 at 09:34
  • sorry I meant that it is an option. Request should send either ObjectOne or ObjectTwo, I want to throw an exception if they send both. – BST Feb 26 '14 at 09:36

0 Answers0