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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:17:24+00:00 2026-06-05T12:17:24+00:00

I work with a datamodel created using JAXB, from that I can generate XML

  • 0

I work with a datamodel created using JAXB, from that I can generate XML directly

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#" xmlns:ext="http://musicbrainz.org/ns/ext#-2.0">
<artist-list offset="0" count="1">
   <artist ext:score="100" type="Group" id="4302e264-1cf0-4d1f-aca7-2a6f89e34b36">       
       <name>Farming Incident</name>
       <ipi-list>
          <ipi>1001</ipi>
       </ipi-list>
   </artist>
</artist-list>
</metadata>

and with the help of Jersey also generate JSon using Natural notation

"artist-list":
    {"offset":0,
     "count":1,
     "artist":[
         {"score":"100",
          "type":"Group",
          "id":"4302e264-1cf0-4d1faca7-2a6f89e34b36",
          "name":"Farming Incident",
          "ipi-list":
              {
                  "ipi":[
                       "1001"
                    ]
             }
          }]
     }

The Xml is fine, the json is nearly fine except that because Json directly supports arrays having elements like ipi-list and artist-list doesnt seem very json, is it possible to generate more json like json from my model ?

Additional Information as Requested
The json is generated from this MMD schema
http://svn.musicbrainz.org/mmd-schema/trunk/brainz-mmd2-jaxb/src/main/resources/musicbrainz_mmd-2.0.xsd using JAXB and Jersey ,
see
http://svn.musicbrainz.org/search_server/trunk/servlet/src/main/java/org/musicbrainz/search/servlet/mmd2/ResultsWriter.java and
http://svn.musicbrainz.org/search_server/trunk/servlet/src/main/java/org/musicbrainz/search/servlet/mmd2/ArtistWriter.java

The point is that I want to be able to generate Json and XML from one schema with the minimum of fuss, but apparently the Json doesn’t look right so Im looking for a way to improve it (I don’t really have any experience of json myself)

  • 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-05T12:17:26+00:00Added an answer on June 5, 2026 at 12:17 pm

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

    You could leverage the JSON-Binding and external mapping document in EclipseLink JAXB (MOXy) to support your use case.

    External Mapping File (oxml.xml)

    You can use the @XmlPath(".") extension in MOXy to flatten parts of your object model. Specify a path of "." tells MOXy to include the referenced object in the parent node.

    <?xml version="1.0"?>
    <xml-bindings
        xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
        package-name="forum10699038">
        <java-types>
            <java-type name="Metadata">
                <java-attributes>
                    <xml-element java-attribute="artistList" xml-path="."/>
                </java-attributes>
            </java-type>
            <java-type name="Artist">
                <java-attributes>
                    <xml-element java-attribute="ipiList" xml-path="."/>
                </java-attributes>
            </java-type>
        </java-types>
    </xml-bindings>
    

    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 model with the following entry.

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

    Demo

    The code below populates the object model from your XML document, and then marshalled to JSON. It demonstrates how to leverage the external mapping file and put MOXy in JSON mode.

    package forum10699038;
    
    import java.io.File;
    import java.util.*;
    import javax.xml.bind.*;
    
    import org.eclipse.persistence.jaxb.JAXBContextProperties;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            // READ FROM XML
            JAXBContext jcXML = JAXBContext.newInstance(Metadata.class);
    
            File xml = new File("src/forum10699038/input.xml");
            Unmarshaller unmarshaller = jcXML.createUnmarshaller();
            Metadata metadata = (Metadata) unmarshaller.unmarshal(xml);
    
            // WRITE TO JSON
            Map<String, Object> properties = new HashMap<String, Object>(3);
            properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, "forum10699038/oxm.xml");
            properties.put(JAXBContextProperties.MEDIA_TYPE, "application/json");
            properties.put(JAXBContextProperties.JSON_INCLUDE_ROOT, false);
            JAXBContext jcJSON = JAXBContext.newInstance(new Class[] {Metadata.class}, properties);
    
            Marshaller marshaller = jcJSON.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.marshal(metadata, System.out);
        }
    
    }
    

    Output

    {
       "artist" : [ {
          "id" : "4302e264-1cf0-4d1f-aca7-2a6f89e34b36",
          "type" : "Group",
          "score" : "100",
          "name" : "Farming Incident",
          "ipi" : [ "1001" ]
       } ]
    }
    

    MOXy and Jersey

    You can easily use MOXy as your JSON provider in a JAXB-RS environment such as Jersey:

    • http://blog.bdoughan.com/2012/05/moxy-as-your-jax-rs-json-provider.html

    OTHER FILES

    Below are versions of your files I created to make sure everything worked properly.

    input.xml

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#" xmlns:ext="http://musicbrainz.org/ns/ext#-2.0">
        <artist-list offset="0" count="1">
            <artist ext:score="100" type="Group"
                id="4302e264-1cf0-4d1f-aca7-2a6f89e34b36">
                <name>Farming Incident</name>
                <ipi-list>
                    <ipi>1001</ipi>
                </ipi-list>
            </artist>
        </artist-list>
    </metadata>
    

    Metadata

    package forum10699038;
    
    import javax.xml.bind.annotation.*;
    
    @XmlRootElement
    public class Metadata {
    
        @XmlElement(name="artist-list")
        ArtistList artistList;
    
    }
    

    ArtistList

    package forum10699038;
    
    import java.util.List;
    
    public class ArtistList {
    
        private List<Artist> artist;
    
    }
    

    Artist

    package forum10699038;
    
    import javax.xml.bind.annotation.*;
    
    @XmlType(propOrder={"name", "ipiList"})
    public class Artist {
    
        @XmlAttribute
        private String id;
    
        @XmlAttribute
        private String type;
    
        @XmlAttribute(namespace="http://musicbrainz.org/ns/ext#-2.0")
        private String score;
    
        @XmlElement(name="ipi-list")
        private IPIList ipiList;
    
        private String name;
    
    }
    

    IPList

    package forum10699038;
    
    import java.util.List;
    
    public class IPIList {
    
        private List<String> ipi;
    
    }
    

    package-info

    @XmlSchema( 
        namespace = "http://musicbrainz.org/ns/mmd-2.0#", 
        elementFormDefault = XmlNsForm.QUALIFIED,
        xmlns={
            @XmlNs(prefix="", namespaceURI = "http://musicbrainz.org/ns/mmd-2.0#")
        }
    ) 
    @XmlAccessorType(XmlAccessType.FIELD)
    package forum10699038;
    
    import javax.xml.bind.annotation.*;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hibernate can auto-generate schemas from properly annotated POJO classes. And I also know that
I have an application that contains methods that work with data using Entity Framework
I'm using Sencha touch 2. I have store that load from existing js object:
I can't get my application to work using MVC architecture. Here is the code:
I'm trying to parse that document with SAX: <scxml version=1.0 initialstate=start name=calc> <datamodel> <data
work on SQL Server 2000. want to Automated Email Notifications using SQL Server Job
Work on a support helpdesk. New tickets come in and records are created in
I work in a group that does a large mix of research development and
At work, we have migrated from Windows XP to Windows Vista. After the migration,
I have an application that needs to join tables from multiple databases into a

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.