-4

I've been MOXy an object mapper that can use XPath to map variables from one object or an XML web service response to another object through annotations.

(https://www.eclipse.org/eclipselink/documentation/2.4/moxy/advanced_concepts005.htm). Here's an example:

@XmlPath("node[@name='first-name']/text()")
private String firstName;

However it doesn't support the xpath 'parent' (EclipseLink MOXy @XmlPath support for axes/parent) or 'child'(eclipselink moxy xpath - selecting all child elements of the current node or all elements in a document with a particular name) checks.

ie: this is an example of what I want to be able to do:

XML:

<Customer>
  <Field>
    <Type>Code</Type>
    <Value>abc</Value>
  </Field>
  <Field>
    <Type>Name</Type>
    <Value>cde</Value>
  </Field>
  ...
</Customer>

Java

@XmlPath("Customer/Field[child::Type='Code']/Value/text()")
private String CustomerCode;

Is there a work around to MOXy or add on libraries for parent/child checks?

Community
  • 1
  • 1
JackDev
  • 11,003
  • 12
  • 51
  • 68
  • 1
    In which direction do you want the mapping to work: XML --> Java, or Java --> XML? – Dimitre Novatchev Feb 08 '16 at 04:24
  • 1
    -1: Questions asking us to recommend or find a book, tool, **software library**, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it. *Bounty saved for closing*. – mico Feb 11 '16 at 18:59
  • @Dimitre: From XML --> Java. – JackDev Feb 18 '16 at 04:48
  • @Mico: What I'm asking is a way to achieve this using a MOXy, I've done so much research on this (referenced urls in post) and haven't found any solution. It'll be good if it can be done in MOXy, but I'm open to other suggestions if there's any. I will rephrase my question. – JackDev Feb 18 '16 at 04:51

1 Answers1

1

There are many libraries. Some of them are:
1. JiBX
2. XStream
3. JAXB
4. XMLBeans

XStream is widely used and pretty good

Ghayel
  • 1,113
  • 2
  • 10
  • 19
  • 2
    Please do not answer questions that ask for tool or library recommendations. Answering them encourages people to ask this kind of questions, while they are off-topic on Stackoverflow. Instead, flag or vote to close such questions. – Mathias Müller Feb 14 '16 at 16:56