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 958183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:49:20+00:00 2026-05-16T00:49:20+00:00

I have an abstract class that looks as follows. public abstract class Entity<PK extends

  • 0

I have an abstract class that looks as follows.

public abstract class Entity<PK extends Serializable> implements Serializable {

    private PK id;

    //getters and setters generated here....
}

public class User extends Entity<Long> {

   //all attributes, getters and setters are done here...
}

My Service looks like this

public interface EntityService {

   public void create(Entity<? extends Serializable> entity) throws ServiceException;
   public boolean delete(Entity<? extends Serializable> entity) throws ServiceException;
}

and my implementation is on class EntityServiceImpl.

When I do a Web Service generation with Apache CXF, I get the following exception:

Error: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.reflect.TypeVariable

java.lang.RuntimeException: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.reflect.TypeVariable
    at org.apache.cxf.frontend.AbstractServiceFactory.createService(AbstractServiceFactory.java:41)
    at org.apache.cxf.tools.java2wsdl.processor.JavaToWSDLProcessor.process(JavaToWSDLProcessor.java:128)
    at org.apache.cxf.tools.java2ws.JavaToWSContainer.processWSDL(JavaToWSContainer.java:109)
    at org.apache.cxf.tools.java2ws.JavaToWSContainer.execute(JavaToWSContainer.java:75)
    at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:103)
    at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:58)
    at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:40)
    at org.apache.cxf.tools.java2ws.JavaToWS.run(JavaToWS.java:77)
    at org.apache.cxf.tools.java2ws.JavaToWS.main(JavaToWS.java:45)
Caused by: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.reflect.TypeVariable
    at org.apache.cxf.jaxb.JAXBContextInitializer.addType(JAXBContextInitializer.java:232)
    at org.apache.cxf.jaxb.JAXBContextInitializer.addType(JAXBContextInitializer.java:211)

My question:

How do I generate a Web Service that has Parametrized Types or uses Generics?

  • 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-16T00:49:20+00:00Added an answer on May 16, 2026 at 12:49 am

    Seeing that nobody answered this question, I’ll answer this myself.

    With Apache CXF, A WS generated bean, all getters return a not null object, meaning that if a variable is null, this is what happens:

     public List<? extends User> getParents() {
            if (parents == null) {
                parents = new ArrayList<User>();
            }
            return this.parents;
        }
    

    As you can see, this following causes an exception for CXF:

    • A Serializable class is an interface, so if I have a variable of type Serializable, new Serializable() cannot be defined when CXF generates client source-code.
    • All Object must implement a public constructor.

    Failure for the 2 principles, causes the exception above.


    Solution

    For attribute private List<? extends User> parents, we added this.

    @XmlElements({ 
        @XmlElement(type=Man.class),
        @XmlElement(type=Female.class),
        @XmlElement(type=Child.class)
    })
    private List<? extends User> parents;
    

    And for interfaces, we used the XmlJavaTypeAdapter and wrote an adapter for every implemented subclasses of that interface,

    e.g.

    public class IntegerConstraintBaseAdapter extends XmlAdapter<IntegerConstraint, ConstraintBase<Integer>> {
    
        /* (non-Javadoc)
         * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
         */
        @Override
        public IntegerConstraint marshal(ConstraintBase<Integer> v) throws Exception {
            // TODO Auto-generated method stub
            return null;
        }
    
        /* (non-Javadoc)
         * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
         */
        @Override
        public ConstraintBase<Integer> unmarshal(IntegerConstraint v) throws Exception {
            // TODO Auto-generated method stub
            return null;
        }
    }
    

    Hope this helps someone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have code that looks like this: public abstract class ResourceDownloaderBaseImpl implements
I have a model that looks something like this: public abstract class Parent {
I have an abstract class that implements IDisposable, like so: public abstract class ConnectionAccessor
What if I have a class that both extends an abstract class and implements
I have a model that looks like this: @MappedSuperclass @AccessType(field) public abstract class BaseEntity
I have a class that inherits from Page, called APage. public abstract class APage:
First suppose that I have an abstract class, let's call it AbstractClass. Suppose public
I'm looking at some Java classes that have the following form: public abstract class
I have one class called Person that basically looks like: public class Person {
In C# I have an intrusive tree structure that looks like this: public abstract

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.