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

  • Home
  • SEARCH
  • 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 7780563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:56:19+00:00 2026-06-01T18:56:19+00:00

I am looking for a Java library to convert my domain objects into a

  • 0

I am looking for a Java library to convert my domain objects into a flattened JSON

eg.

public class Person {
   String name
   Address homeAddress
}

public class Address {
  String street
  String zip
}

JSON: {name:'John', homeAddress_street: '123 Street', homeAddress_zip: 'xxxxx'}

I’ve looked into XStream, Eclipse MOXy, FlexJSON, JSON-lib & gson

My goal is to get rid of my json wrapper classes and minimize code. I would like to have a general service that would take any domain model class I have and get a json representation without having to write xml descriptors or any custom converters for each type of model. A depth of 1 level deep is sufficient for my models. I have not found an easy generic solution using annotations or built in functionality in the above libraries but I have probably overlooked them. Is there a non intrusive library that can do this? or maybe one that I’ve listed? I’m using Hibernate so the library must be able to deal with CGLib Proxies

  • 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-01T18:56:21+00:00Added an answer on June 1, 2026 at 6:56 pm

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

    Below is an example of how this could be done with MOXy by leveraging the @XmlPath extension.

    Person

    package forum7652387;
    
    import javax.xml.bind.annotation.*;
    import org.eclipse.persistence.oxm.annotations.XmlPath;
    
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Person {
        String name;
    
        @XmlPath(".")
        Address homeAddress;
    }
    

    Address

    package forum7652387;
    
    import javax.xml.bind.annotation.*;
    
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Address {
        @XmlElement(name="homeAddress_street")
        String street;
    
        @XmlElement(name="homeAddress_zip")
        String zip;
    }
    

    jaxb.properties

    To specify MOXy as your JAXB provider you need to add a file called jaxb.properties in the same package as your domain classes with the following entry:

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

    Demo

    package forum7652387;
    
    import java.io.StringReader;
    import javax.xml.bind.*;
    import javax.xml.transform.stream.StreamSource;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            JAXBContext jc = JAXBContext.newInstance(Person.class);
    
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            unmarshaller.setProperty("eclipselink.media-type", "application/json");
            unmarshaller.setProperty("eclipselink.json.include-root", false);
            String jsonString = "{\"name\":\"John\", \"homeAddress_street\":\"123 Street\", \"homeAddress_zip\":\"xxxxx\"}";
            StreamSource jsonSource = new StreamSource(new StringReader(jsonString));
            Person person = unmarshaller.unmarshal(jsonSource, Person.class).getValue();
    
            Marshaller marshaller = jc.createMarshaller();
            marshaller.setProperty("eclipselink.media-type", "application/json");
            marshaller.setProperty("eclipselink.json.include-root", false);
            marshaller.marshal(person, System.out);
        }
    
    }
    

    Output

     {"name" : "John", "homeAddress_street" : "123 Street", "homeAddress_zip" : "xxxxx"}
    

    For More Information

    • http://blog.bdoughan.com/2011/08/json-binding-with-eclipselink-moxy.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking into compressing binary data, more specifically serialized Java objects. I think I
I am looking for a Java library to incorporate into a demo web app
I am looking for a java library/class to parse clean URL's and get all
Is their an easy way or library to convert a JSON String to a
I am looking for a Java library which can convert Non-deterministic Finite Automaton to
I'm looking for a Java library that evaluates REST-style URLs. Something like: public Result
I'm looking for a Java library which can notify me about changes on the
I'm looking for a java library that works on the android that can download
I am looking for a Java library to do some initial spell checking /
I'm looking for a Java library for converting values that supports generic types. That

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.