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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:29:21+00:00 2026-06-17T20:29:21+00:00

Is it possible to use @XmlValue annotation on a referenced object annotated with @XmlElementRef?

  • 0

Is it possible to use @XmlValue annotation on a referenced object annotated with @XmlElementRef? The goal is to produce the following XML output:

    <foo>
       <bar>Blah</bar>
    </foo>

Given the following example JAXBContext initialization is throwing a NPE:
at com.sun.xml.bind.v2.runtime.property.PropertyFactory.create(PropertyFactory.java:128)

Foo Class

     @XmlRootElement(name = "foo")
     public class Foo
     {
         @XmlElementRef
         private Bar bar;
     }

Bar Class

     @XmlRootElement(name = "bar")
     public class Bar extends BarBase // BarBase is annotated with @XmlTransient
     {
         @XmlValue
         private String value;
     }

Is there any way to achieve the desired output based on the implementation? I’ve been looking into Adapters, but haven’t been successful at implement one. Thanks in advance!

  • 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-17T20:29:22+00:00Added an answer on June 17, 2026 at 8:29 pm

    Note: I’m the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group.

    JAXB RI Issue Confirmed

    I have been able to confirm the issue you are seeing with the JAXB RI. I get the following stack trace:

    Exception in thread "main" java.lang.NullPointerException
        at com.sun.xml.internal.bind.v2.runtime.property.PropertyFactory.create(PropertyFactory.java:113)
        at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.<init>(ClassBeanInfoImpl.java:166)
        at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXBContextImpl.java:494)
        at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:311)
        at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:126)
        at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1148)
        at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:130)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:248)
        at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:235)
        at javax.xml.bind.ContextFinder.find(ContextFinder.java:445)
        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:637)
        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:584)
        at forum14490548.Demo.main(Demo.java:10)
    

    This is a bug in the JAXB RI and I would recommend opening a ticket at the following link:

    • http://java.net/jira/browse/JAXB/

    Option #1 – Use an Alternate Mapping with JAXB RI

    The following mapping appears to work with the JAXB RI (using @XmlElement instead of @XmlElementRef.

    import javax.xml.bind.annotation.*;
    
    @XmlRootElement(name = "foo")
    public class Foo
    {
        @XmlElement
        private Bar bar;
    }
    

    Option #2 – Use an Alternate JAXB (JSR-222) Provider

    Your mappings are correct. If you use another JAXB (JSR-222) provider such as EclipseLink MOXy you will not get this exception. Below is a link that explains how to use MOXy as your JAXB provider:

    • http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Use Linq to Xml with Xml namespaces I have an xml: <?xml
Is it possible use mod_rewrite to resolve addresses hosted on another server? Say I
Is it possible use a MySQL query to perform this kind of check? If
I need a control having these features: It should be possible use it in
Is possible to use ArcSDE API in .NET(C#) ? http://edndoc.esri.com/arcsde/9.2/api/capi/dbconnects/dbconnects.htm Thanks
Is this possible to use Ajax.Beginform with update target inside of ajax form. like
Is it possible to use JMF in Android? JMF has good functionality? I'm basically
Is it theoretically possible to use in-app purchases to update an iOS app automatically?
is it possible to use chaplin with meteor? Any idea, advice, pointers or guidance
Is it possible to use a vector graphic as a custom form shape in

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.