Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5947467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:58:05+00:00 2026-05-22T16:58:05+00:00

I have a Web Service created in Java (1.6), with metro (2.0), using maven,

  • 0

I have a Web Service created in Java (1.6), with metro (2.0), using maven, under Tomcat 6.
In all web methods the return type is a generic 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 example:

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

And in 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();

In some web methods it is working.
But when the result is a class with have a List<? class> attribute, it fails to unmarshal.

This project is part of a biggest one. So for test purposes I created a new one, simpler, just the project, with the same data model, and copy one of the web methods, in this case it worked, and after unmarshal, I had a result that i could cast to the expected type.

What could be happening?

EDIT:

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:58:06+00:00Added an answer on May 22, 2026 at 4:58 pm

    I’m not really sure if I fully understand your problem, but to me it seems you expect a little too much from JAXB here. Your WsResult is generic in the unrestricted parameter T, which means at runtime there’s nothing left but an Object reference for JAXB to play with.

    What JAXB really needs to deal with such a situation is, loosely speaking, a hint on which class to instantiate to fill the result field. To fill this in you should either

    • create concrete subclasses of WsResult (like, following your example, class OtherClassResult extends WsResult<OtherClass> — when you throw the OtherClassResult at JAXB, it will know that result needs to be an instance of OtherClass and has a chance to act accordingly or
    • annotate the result field with @XmlElements, like this:
    @XmlElements({
        @XmlElement(name = "text", type = String.class), // add more elems here
        @XmlElement(name = "other", type = OtherClass.class)})
    protected Object result;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a simple web-service using Java. i want to load jars related
I have created a web service which has a couple of methods developed using
I have created a web service in a virtual directory using VS 2008. I
I have created a Web Service (with Java, Axis). Depending on the content of
I have a java web service application, i created a .WAR file. and now
I have a java web service application, i created a .WAR file. and now
In java i have created a JAX- web service, which is up and running,
We have created a web service using JAX-WS and ProSyst OSGi. Accessing the service
I have created one application in flex that is accessing the Java webservice using
I have a web service that I created in C# and a test harness

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.