Unmarshal generates a null field in generic with a List <T> field

I have a web service created in Java (1.6), with the subway (2.0), using maven, under Tomcat 6. In all web methods, the return type is a common class:

public class WsResult<T> {
    protected T result;          // the actual result
    protected Code requestState; // 0K, or some error code if needed
    protected String message;    // if error, instead of result, insert a message
}

For instance:

public WsResult<OtherClass> someMethod(...);
public WsResult<Foo> someMethod_2(...);

And in the client:

MyServiceService service = new MyServiceService();
MyService port = service.getMyServicePort();

WsResult result = port.someMethod(...);
OtherClass oc = (OtherClass) result.getResult();

WsResult res = port.someMethod_2(...);
Foo o = (Foo) res.getResult();

It works in some web methods. But when the result is a class with an attribute List<? class>, it cannot be undone.

This project is part of the largest. Therefore, for test purposes, I created a new, simpler, simple project, with the same data model and copied one of the web methods, in this case it worked, and after immediate, I had a result that I could apply to the expected type .

What can happen?

EDIT:

The answer is yes, but generates a getter for each type added to the field declaration. Is there a better way?

+5
1

, , , JAXB . WsResult T, , , Object JAXB .

, JAXB , - , , , result. ,

  • WsResult (, , class OtherClassResult extends WsResult<OtherClass> - OtherClassResult JAXB, , result OtherClass
  • result @XmlElements, :
@XmlElements({
    @XmlElement(name = "text", type = String.class), // add more elems here
    @XmlElement(name = "other", type = OtherClass.class)})
protected Object result;
+3

All Articles