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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:14:18+00:00 2026-05-24T03:14:18+00:00

I have some old code (pre Java 1.5) that uses classes to implement type

  • 0

I have some old code (pre Java 1.5) that uses classes to implement type safe enums, something like:

public class MyTypeSafeEnum implements java.io.Serializable {
  private final int value;

  private  MyTypeSafeEnum(int value) {
   this.value = value
  }

  public static final MyTypeSafeEnum FIRST_VALUE = new MyTypeSafeEnum(0)
  public static final MyTypeSafeEnum SECOND_VALUE = new MyTypeSafeEnum(1)
  public static final MyTypeSafeEnum THIRD_VALUE = new MyTypeSafeEnum(2)

  public static fromInt(int value) {
   //Builds a MyTypeSafeEnum from the value, implementation omitted
   return theMyTypeSafeEnum;
  }

  public int getValue() {
    return this.value;
  }
 }

I want to use these enumeration classes as paremeters in a JAX-WS operation, but in the generated WSDL the definition for the type is empty:

<xs:complexType name="myTypeSafeEnum">
  <xs:sequence/>
</xs:complexType>

I figured I should use an XmlAdapter, so I created the following class:

public class MyTypeSafeEnumXmlAdapter extends XmlAdapter<MyTypeSafeEnum, Integer> {
  @Override
  public MyTypeSafeEnum marshal(Integer v) throws Exception {
      return MyTypeSafeEnum.fromInt(v);
  }

  @Override
  public Integer unmarshal(MyTypeSafeEnum e) throws Exception {
      return e.getValue();
  }
}

I added the @XmlJavaTypeAdapter(MyTypeSafeEnumXmlAdapter.class) annotation to my class, but it had no effect in the generated WSDL.

How I can use these classes as parameters in a JAX-WS operation? At the moment, refactoring the code to use the enum type is out of question.

  • 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-24T03:14:19+00:00Added an answer on May 24, 2026 at 3:14 am

    You need to reverse the order of the types in your MyTypeSafeEnumXmlAdapter:

    public class MyTypeSafeEnumXmlAdapter extends XmlAdapter<Integer, MyTypeSafeEnum> {
        @Override
        public Integer marshal(MyTypeSafeEnum v) throws Exception {
            return v.getValue();
        }
    
        @Override
        public MyTypeSafeEnum unmarshal(Integer v) throws Exception {
            return MyTypeSafeEnum.fromInt(v);
        }
    }
    

    So then if you have a class like this:

    public class MyClass {
        private MyTypeSafeEnum someVar;
    
        @XmlJavaTypeAdapter(MyTypeSafeEnumXmlAdapter.class)
        public MyTypeSafeEnum getSomeVar() {
            return someVar;
        }
    }
    

    It will generate the XML like this:

    <xs:complexType name="myClass">
        <xs:sequence>
            <xs:element minOccurs="0" name="someVar" type="xs:int"/>
        </xs:sequence>
    </xs:complexType>
    

    The web service clients will see that field as an integer. So you’ll have to make sure they don’t pass in an integer that doesn’t map to one of the enum instances, or handle it somehow.

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

Sidebar

Related Questions

I have some old C code that I would like to combine with some
I have some old python code that uses the pywin32 extensions. Starting out with
I have some old code in Javascript that interfaces to Java DWR . I'm
We have some old C code here that's built with nmake. Is there an
We have some really old code that calls WebServices using behaviours (webservice.htc), and we
I have some old code that I'm converting to use in Windows Phone. The
I have some old Haskell code that includes QuickCheck test cases. Newer versions of
I have some old school looking code that is as follows: IList<KeyValuePair<string, ValuePair>> ServicePairs
I was reviewing some of my old code and I have a method that
While refactoring some old code I have stripped out a number of public methods

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.