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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:24:24+00:00 2026-06-08T18:24:24+00:00

I have a considerably big POJO domain model built incrementally since 2005. We also

  • 0

I have a considerably big POJO domain model built incrementally since 2005. We also have the XSD incrementally developed over the same time frame. Currently, I use xmlbeans in the following way to generate xml to be sent over HTTP and as part of WebService response.

  1. Generate binding code from XSD using xmlbeans
  2. Wrote lot of mappers that populate binding code from my domain POJO (also the reverse)
  3. Marshall it to XML
  4. Incase of Web Services, we use Axis 1.4 which can use the Serialization/Desrialization factories generated by xmlbeans. This allows us the have the same code to be reused across two endpoints: XML over HTTP and SOAP/HTTP

Now, we would like to start using JAXB as it is mature, standard, supports multi-tenancey (atleast the Moxy implementation) and also not much work is being done as part of xmlbeans anymore. So my questions are

  1. How to use JAXB without generating the binding code. i.e. I doesn’t want to write or maintain the mapping code (Step 2) anymore. I am wondering if I can somehow use the JAXB to unmarshal to my domain POJO directly?
  2. How to integrate this with my WebService? My webservice uses the same schema and doesnt want to replicate the mappings.
  3. Any other best practice suggestions?
  4. Any Gotchas/Lessons learned I should be aware of?
  • 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-08T18:24:25+00:00Added an answer on June 8, 2026 at 6:24 pm

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

    1 – How to use JAXB without generating the binding code. i.e. I doesn’t
    want to write or maintain the mapping code (Step 2) anymore. I am
    wondering if I can somehow use the JAXB to unmarshal to my domain POJO
    directly?

    The key to using your own domain objects is path based mapping. Without this the model used by your binding framework must closely resemble the XML document. Below is a sample I like to give where a simple address object is mapped to the result of Google Geocoding API V2.

    package blog.geocode;
    
    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.XmlType;
    
    import org.eclipse.persistence.oxm.annotations.XmlPath;
    
    @XmlRootElement(name="kml")
    @XmlType(propOrder={"country", "state", "city", "street", "postalCode"})
    public class Address {
    
        @XmlPath("Response/Placemark/ns:AddressDetails/ns:Country/ns:AdministrativeArea/ns:SubAdministrativeArea/ns:Locality/ns:Thoroughfare/ns:ThoroughfareName/text()")
        private String street;
    
        @XmlPath("Response/Placemark/ns:AddressDetails/ns:Country/ns:AdministrativeArea/ns:SubAdministrativeArea/ns:Locality/ns:LocalityName/text()")
        private String city;
    
        @XmlPath("Response/Placemark/ns:AddressDetails/ns:Country/ns:AdministrativeArea/ns:AdministrativeAreaName/text()")
        private String state;
    
        @XmlPath("Response/Placemark/ns:AddressDetails/ns:Country/ns:CountryNameCode/text()")
        private String country;
    
        @XmlPath("Response/Placemark/ns:AddressDetails/ns:Country/ns:AdministrativeArea/ns:SubAdministrativeArea/ns:Locality/ns:PostalCode/ns:PostalCodeNumber/text()")
        private String postalCode;
    
    }
    

    Below is a link to an example where the same object model is mapped to both the Google and Yahoo weather services:

    • http://blog.bdoughan.com/2011/09/mapping-objects-to-multiple-xml-schemas.html

    2 – How to integrate this with my WebService? My webservice uses the same schema and doesnt want to replicate the mappings.

    If Axis supports multiple JAXB providers then you should be able to leverage MOXy without much configuration. Potentially just by adding a jaxb.properties file in the same package as your domain model.

    • http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html

    3 – Any other best practice suggestions?

    If you want to avoid adding any compile time dependencies into your domain model, then you may want to consider representing the metadata as XML.

    • http://blog.bdoughan.com/2010/12/extending-jaxb-representing-annotations.html

    UPDATE

    The following are the answers to the questions you made via comments:

    One restriction I know with the webservice API’s is that they work
    against the “factories generated by the xjc.” In which case I believe
    I can no longer use the XPath mapping. Please correct me if I am
    wrong. Also, If I use annotations, should I still need to use xjc?

    I’m not sure about CXF, but standard JAX-WS implementations allow you to start from your own domain model, or generate one via XJC. Below are a couple of examples of using MOXy in a JAX-WS environment when you start with Java objects:

    • http://blog.bdoughan.com/2011/12/eclipselink-moxy-is-jaxb-provider-in.html
    • http://blog.bdoughan.com/2012/02/glassfish-312-is-full-of-moxy.html

    I assume this is another option other than using XPath and is also the
    only option if I need to support multi-tenancy.

    The external mapping document isn’t an alternative to XPath, it’s just another way to specify the metadata. Some people prefer this approach if they don’t want to introduce any MOXy dependencies on classes that will be used for more that just object-to-XML or object-to-JSON conversions. For multi-tenancy I often annotate all the shared properties, and then have a mapping document per tenant to map the extensions.

    • http://blog.bdoughan.com/2011/06/moxy-extensible-models-multi-tenant.html

    Also, are there any performance implications if I go the XPath route
    or if i chose metadata in XML?

    There aren’t any performance implications of using path based mapping. This all gets optimized when the JAXBContext is initialized. When bootstrapping for an external binding document the JAXBContext creation is slightly slower as a little more work is being done, but as JAXB/MOXy is configuration by exception these documents tend to be small. There is no impact on the Marshaller/Unmarshaller of using external mapping documents.

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

Sidebar

Related Questions

I have an ASP.NET website that I built that has grown considerably in size
Have deployed numerous report parts which reference the same view however one of them
I have a the following selenium test suite inheriting from the same base class,
I have noticed that rendering of fonts differ considerably if the size is, for
I have already cut everything I could from the main loop. I also optimized
I have bug checked this code considerably now and made sure I am outputting
I have noticed that considerably amount of questions in SO, relating to Python, are
I have a SQL Server 2005 database from which I'm removing several large tables
I have an in-house iPhone app. Developed about a year and a half ago.
We are developing a considerably big application using Ruby on Rails framework (CRM system)

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.