0

I need to perform some calls to a backend not managed by me. The point is that they use different xml format to trasport the data. Even for the same call request and response are different: same data but different root tags. At first I tried to map them with different beans using annotations (moxy jaxb), but the I had to manage to many of them and rhe cost of change was too high. Then I switched to xml file mapping: it seems better then previous choice, but still I have to manage lots of xml files (douzen). Have you got any proposal in order to keep the project light and scalable?

Thanks in advance for the help.

Pirulino
  • 758
  • 1
  • 9
  • 20
  • [What have you tried so far?](http://mattgemmell.com/what-have-you-tried) – Shreyos Adikari Mar 27 '14 at 21:42
  • As I said, I tried to create different beans but doing so I had to manage more then 15 objects only for the communication. The xml binding files choice seems better, but it doesn't satisfy me since I moved the complexity from java objects to xml files. Still searching.... – Pirulino Mar 27 '14 at 21:46

1 Answers1

2

One of the reasons we added the external mapping document in EclipseLink JAXB (MOXy) is to allow you to apply additional XML representations to your object model:

One thing to pay attention to is the xml-mapping-metadata-complete attribute on the root xml-bindings element. When this is set to true the XML document replaces all other mappings, and when it is false or not present it amends the metadata.

<?xml version="1.0"?>
<xml-bindings
    xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
    package-name="blog.weather"
    xml-mapping-metadata-complete="true">

Using the amend the metadata approach you can pass in multiple binding files to create the Context where subsequent mapping files can be used to progressively tweak the metadata.

    Map<String, Object> properties = new HashMap<String, Object>(1);
    List<String> bindingFiles = new ArrayList<String>(2);
    bindingFiles.add("version2.xml");
    bindingFiles.add("version3.xml");
    properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, bindingFiles);
    JAXBContext jc = JAXBContext.newInstance(new Class[] {WeatherReport.class}, properties);
bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • 1
    I agree this a good solution, but doing so I would have several binding files. Many thanks for the help. – Pirulino Mar 28 '14 at 18:44