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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:09:05+00:00 2026-06-06T09:09:05+00:00

I am using EclipseLink dynamic moxy for jaxb. When I try to set an

  • 0

I am using EclipseLink dynamic moxy for jaxb. When I try to set an enum value, I get a ClassNotFound exception. Can anyone point out what I am doing wrong?

Schema:

<xs:element name="customer" type="customerType"> </xs:element>

 <xs:complexType name="customerType">
    <xs:sequence>
        <xs:element name="number" type="numberEnum"/>
        <xs:element name="name" type="xs:string"/>
    </xs:sequence>
</xs:complexType>

<xs:simpleType name="numberEnum">
    <xs:restriction base="xs:string">
        <xs:enumeration value="1"/>
        <xs:enumeration value="2"/>
        <xs:enumeration value="3"/>
    </xs:restriction>
</xs:simpleType>

Java code:

    package uic;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import javax.xml.bind.JAXBException;

import org.eclipse.persistence.dynamic.DynamicEntity;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory;

public class test{

DynamicJAXBContext context;

test() {
    try{
        context = DynamicJAXBContextFactory.createContextFromXSD(new FileInputStream(new File("sample/NewXMLSchema1.xsd")), null, null, null);
    } catch(JAXBException e) {
        e.printStackTrace();
    } catch(FileNotFoundException e){
        e.printStackTrace();
    }

    DynamicEntity root = context.newDynamicEntity("CustomerType");

    root.set("name", "tom");

    Object enumValue = null;
    try {
        enumValue = context.getEnumConstant("uic.NumberEnum", "2");
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JAXBException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    root.set("Number", enumValue);
}

public static void main(String args[]) {
    new test();
}
}

Am i going wrong when I create the context using createContextFromXSD()? I followed this example: EclipseLink dynamic MOXy accessing enum values

I don’t have a problem when I am accessing other JAXB generated classes. The problem is only for the enum classes. Are they placed in a different package from the other generated classes or something?

Edit: In the main program, I receive an xml schema file as the input. I use an xsom parser to retrieve the element and type declarations, and then marshal using JAXB generated classes, to get the output, an XML file. So, any changes I need to do to the schema will have to be done dynamically.

Thanks.

  • 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-06-06T09:09:06+00:00Added an answer on June 6, 2026 at 9:09 am

    I am a developer on the EclipseLink product and have been looking at your issue. A NumberEnum class was not generated because the enumeration values are all numbers, which is invalid for a Java enum. If you were to run your schema through the xjc command-line tool, you would also see that no enum class was generated.

    One solution would be to change your enum values to ONE, TWO, THREE, if you have the flexibility of changing your schema.

    Otherwise, the standard way to get around this would be with the use of a JAXB bindings file, to customize the enum values:

        <jxb:bindings
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
            version="2.1">
            <jxb:bindings schemaLocation="schema.xsd">
    
                <jxb:bindings node="//xs:simpleType[@name='numberEnum']/xs:restriction/xs:enumeration[@value='1']">
                    <jxb:typesafeEnumMember name="ONE"/>
                </jxb:bindings>
    
                <jxb:bindings node="//xs:simpleType[@name='numberEnum']/xs:restriction/xs:enumeration[@value='2']">
                    <jxb:typesafeEnumMember name="TWO"/>
                </jxb:bindings>
    
                <jxb:bindings node="//xs:simpleType[@name='numberEnum']/xs:restriction/xs:enumeration[@value='3']">
                    <jxb:typesafeEnumMember name="THREE"/>
                </jxb:bindings>
    
            </jxb:bindings>
        </jxb:bindings>
    

    However, we currently have a bug in EclipseLink Dynamic JAXB, and this enum customization is not being taken into account. We are working on this for our 2.4.1 release, you can track the progress of this bug here:

    https://bugs.eclipse.org/bugs/show_bug.cgi?id=383575

    Thanks,

    Rick

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

Sidebar

Related Questions

I'm using EclipseLink's MOXy as the JAXB implementation in my RESTEasy project.MOXy's advanced functionality
Has anyone got EclipseLink MOXy (I'm using eclipselink 2.1.0) to work with Java 5?
How can I get changed attributes (name, old value, new value) on update using
Using Eclipselink/MOXy 2.3 i have following usecase in marshalling to XML: abstract class MyAbstract
I'm using EclipseLink 2.3.1 to model self referencing table with JPA 2. I get
Using JPA 2 with EclipseLink implementation. I'm trying to build a dynamic query which
I have following use-case for marshalling a POJO to XML using Eclipselink MOXy 2.3:
Hi, I am using the EclipseLink API to create dynamic entities to represent a
I'm using EclipseLink on GlassFish 3.1.1 and I'm trying to understand this exception: javax.ejb.EJBException:
To solve another problem I have moved from using Jersey to EclipseLink MOXy to

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.