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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:45:42+00:00 2026-05-20T18:45:42+00:00

I want to know how to implement having List of interface Type using EclipseLink

  • 0

I want to know how to implement having List of interface Type using EclipseLink MOXy,
Before, using JAXB , The following annotations did the job

class A {

   @XmlElements({
       @XmlElement(name = "B1", type = B1.class),
       @XmlElement(name = "B2", type = B2.class)
    })
    List< B > list;

}

interface B{}

class B1 implements B {}

class B2 implements B {} 

to support List of interface type ???

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

    I lead EclipseLink JAXB (MOXy). I am not able to reproduce your issue. Could you provide the stack trace you are seeing? The following is what I have tried:

    Demo

    import java.io.File;
    
    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.JAXBElement;
    import javax.xml.bind.Marshaller;
    import javax.xml.bind.Unmarshaller;
    import javax.xml.transform.stream.StreamSource;
    
    import org.eclipse.persistence.Version;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            System.out.println(Version.getVersionString());
    
            JAXBContext jc = JAXBContext.newInstance(A.class, B1.class, B2.class);
            System.out.println(jc);
    
            File xml = new File("input.xml");
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            JAXBElement<A> root = unmarshaller.unmarshal(new StreamSource(xml), A.class);
    
            Marshaller marshaller = jc.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.marshal(root, System.out);
        }
    
    }
    

    jaxb.properties

    javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
    

    input.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <root>
       <B1/>
       <B2/>
    </root>
    

    Output

    2.2.0.v20110202-r8913
    org.eclipse.persistence.jaxb.JAXBContext@11ddcde
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
       <B1/>
       <B2/>
    </root>
    

    Using EclipseLink JAXB (MOXy)’s XML Metadata File

    MOXy also has an extension to provide the metadata as an XML file. Below is what it would look like for this example:

    <?xml version="1.0"?>
    <xml-bindings
        xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
        package-name="com.example">
        <java-types>
            <java-type name="A">
                <java-attributes>
                    <xml-elements java-attribute="list">
                        <xml-element name="B1" type="com.example.B1"/>
                        <xml-element name="B2" type="com.example.B2"/>
                    </xml-elements>
                </java-attributes>
            </java-type>
        </java-types>
    </xml-bindings>
    

    This metadata file is passed in as a property when the JAXBContext is created:

    Map<String, Object> properties = new HashMap<String, Object>(1);
    properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, new File("src/forum149/bindings.xml"));
    JAXBContext jc = JAXBContext.newInstance(new Class[] {A.class, B1.class, B2.class}, properties);
    

    For more information see:

    • http://bdoughan.blogspot.com/2010/12/extending-jaxb-representing-annotations.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement multi tenancy using Windsor and i don't know how to
want to know why String behaves like value type while using ==. String s1
I want to get distinct items from List in C# by using IEqualityComparer interface.
I know it's simple to implement, but I want to reuse something that already
First, I know about Clog , and I do not want to implement this
I know that this is probably something easy to implement, but I am having
I want to start using modular CSS, but I'm having trouble figuring out the
I want to know, how sockets are implemented in the Java Virtual Machine. Is
i just want to know how the call hierarchy is implemented in eclipse IDE
Want to know what the stackoverflow community feels about the various free and non-free

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.