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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:49:48+00:00 2026-05-26T18:49:48+00:00

I am defining a static factory method with: @XmlType(factoryClass=DummyFactory.class, factoryMethod=createNew) public abstract MyClass() {

  • 0

I am defining a static factory method with:

@XmlType(factoryClass=DummyFactory.class, factoryMethod="createNew")
public abstract MyClass() {
}

The reason I am using factory methods is that MyClass is abstract, and how to obtain an instance of it depends on certain annotations of the class. This logic is embedded in the factory method createNew.

In addition, the factory class DummyFactory is abstract. As far as I understand factory classes do not need to provide a default constructor if their factory method is static (http://download.oracle.com/javaee/6/api/javax/xml/bind/annotation/XmlType.html).

This is a raw simplification of how the factory class looks like:

public abstract class DummyFactory {
    public static MyClass createNew() {
        // code for returning a new instance of MyClass
    }   
}

However, when I try to unmarshal a XML document, I am getting the following exception:

Exception [EclipseLink-171] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The factory class does not define a public default constructor, or the constructor raised an exception.
Internal Exception: java.lang.InstantiationException

First I thought that I did not get something correctly in the explanation of factory classes and methods, but then I tried with JAXB RI and this is working fine there.
So my question is:

Is there a way to make MOXy work with abstract factory classes ?

(JAXB RI is giving me other kind of problems, that is the reason I would prefer not using it).

  • 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-26T18:49:49+00:00Added an answer on May 26, 2026 at 6:49 pm

    Thank you for entering a bug for this issue (https://bugs.eclipse.org/362984). The issue has been fixed in the EclipseLink 2.4 stream, and will be backported today (Nov 9, 2011) to the EclipseLink 2.3.2 stream. You can try out the fix obtaining a nightly download from:

    • http://www.eclipse.org/eclipselink/downloads/nightly.php

    Now if you specify a factory class using the @XmlType annotation like:

    @XmlType(factoryClass=DummyFactory.class, factoryMethod="createNew")
    public abstract MyClass() {
    }
    

    The following types of factory classes are supported:

    Factory with Static Methods

    With this bug fix, when MOXy uses the factory method to create an instance of MyClass an instance of DummyFactory is not created.

    public abstract class DummyFactory {
        public static MyClass createNew() {
            // code for returning a new instance of MyClass
        }   
    }
    

    Factory with Instance Methods

    In addition to static methods, MOXy allows you to specify instance level creation methods. For these methods MOXy will create an instance of the factory class.

    public class DummyFactory {
        public MyClass createNew() {
            // code for returning a new instance of MyClass
        }   
    }
    

    This configuration is not allowed in the JAXB RI, and you will get the following exception:

    Exception in thread "main" com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
    Factory class "forum8022136.DummyFactory" does not have static zero args factory method "createNew".
        this problem is related to the following location:
            at forum8022136.MyClass
    
        at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:91)
        at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:436)
        at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:277)
        at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1100)
        at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:143)
        at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:110)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:202)
        at javax.xml.bind.ContextFinder.find(ContextFinder.java:376)
        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
        at forum8022136.Demo.main(Demo.java:14)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that in this code: class Foo { public static void method() {
In my class I have a static method public static void DoWork(int param) ...
When defining a method on a class in Python, it looks something like this:
I'm defining a class like this: class StaticRuntimeContext { public: enum Verbosity { kHIGH,
How can I find a generic overloaded method? For example, Queryable 's public static
I have been using the static keyword a long time for defining internal linkage.
The StackOverflow question using static keyword in objective-c when defining a cached variable references
I stuck at defining a static pointer inside one of my class which is
having issues with defining a namespace for an abstract class. Class looks like so:
I have Model class like this class ModelName { public static void createTable(SQLiteDatabase db){

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.