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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:11:59+00:00 2026-05-20T01:11:59+00:00

I have the following class that I need to serialize as XML: @XmlAccessorType(XmlAccessType.FIELD) public

  • 0

I have the following class that I need to serialize as XML:

@XmlAccessorType(XmlAccessType.FIELD)
public class Position {

    @XmlElement(name = "Quantity", required = true)
    private DecimalQuantity quantity;

    ...
}

I have put an XmlJavaTypeAdapter on the DecimalQuantity class because I want it to be serialized simply as a BigDecimal without the DecimalQuantity wrapper.

@XmlJavaTypeAdapter(DecimalQuantityAdapter.class)
@Embeddable
public class DecimalQuantity {

    private BigDecimal value;

    ...

}

Here’s the very simple DecimalQuantityAdapter class:

public class DecimalQuantityAdapter
        extends XmlAdapter<BigDecimal, DecimalQuantity> {

    public DecimalQuantity unmarshal(BigDecimal val) throws Exception {
        return new DecimalQuantity(val);
    }

    public BigDecimal marshal(DecimalQuantity val) throws Exception {
        return val.getValue();
    }
}

I have a unit test that shows that the adapter is working correctly. The following Order object that has a DecimalQuantity gets serialized correctly (notice that this test class looks almost identical to the Position class above):

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "Order")
public class Order {

    @XmlElement(name = "Quantity", required = true)
    private DecimalQuantity quantity;

    ...

}

This gets serialized as shown below – no wrapper around the decimal number – life is good!

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Order>
    <Quantity>10.2</Quantity>
</Order>

The trouble starts when I try to use DecimalQuantity in other maven projects. For example, the Position class shown at the beginning of this post is in a different maven project. The web service that uses the Position class is in yet another maven project. When the web service tries to deserialize DecimalQuantity, it does not know what DecimalQuantity is and is not able to pick up the DecimalQuantityAdapter. This is the error I get:

Caused by: javax.xml.bind.JAXBException:
class org.archfirst.common.quantity.DecimalQuantity nor any of its super class is known to this context.
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:594)
    at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:648)
    ... 53 more

I have event tried to add the @XmlJavaTypeAdapter annotation on the attribute itself, but JAXB does not pick it up. The only way to get rid of the exception is to put an @XmlSeeAlso({DecimalQuantity.class}) on the Position class itself. However, this disables the adapter and I get the following (undesired) serialization:

<Quantity xsi:type="ns2:decimalQuantity" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>

Any idea where the problem is? I feel it has something to do with the visibility of JAXB annotations on DecimalQuantity and DecimalQuantityAdapter across packages/projects.

Thanks.

Naresh

  • 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-20T01:12:00+00:00Added an answer on May 20, 2026 at 1:12 am

    Ok, I finally found the problem. My unit test was picking up the JAXB implementation in the Java runtime, whereas my real application (a web service) was picking up the JAXB implementation from GlassFish. Apparently the implementation bundled with GlassFish (2.2.1.1) cannot handle my use case. I proved it by forcing my unit test to use jaxb-impl-2.2.1.1.jar. Also it seems that the bug has been fixed in the latest JAXB implementation (2.2.3-1), but I am struggling to figure out how to replace GlassFish’s implementation with this new version (see my post here).

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

Sidebar

Related Questions

I have the following class that I want to serialize to an XML file
I have a class that looks like the following: public class MyClass { private
We have a class a class that looks something like the following: public class
Given that I have the following WCF service: class LookUpService { public List<County> GetCounties(string
I have a class that I need to binary serialize. The class contains one
Consider the following. You have a class that you want to serialize with XmlSerializer
I have the following class written by someone else that I'm trying to understand
I have the following methods in my Authentication class that is called by my
I have the following ugly if statement that is part of a class that
Assume that we have the following code: class Program { static volatile bool flag1;

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.