3

Edit: My question is similar to the below question: Converting XML to JSON using XML Schema

But:

  1. With Java and not Javascript
  2. In both directions (XML->JSON and JSON->XML)
  3. A general Java library, not related to Node.js
  4. Do it on-the-fly

Something like String json = convertToJSON(xml, xmlSchema)and String xml = convertToXML(json, xmlSchema)

Community
  • 1
  • 1
Kelvin Wayne
  • 87
  • 1
  • 9

1 Answers1

1

The sax2j (schema-aware XML-to-JSON translator) library/tool seems to do the trick. It's only half of the answer since only for the XML->JSON translation, as far as I can see, but it's a start.

cdan
  • 3,470
  • 13
  • 27
  • I need the convertor to be XSD aware so that the conversion respect the definitions in the schema, just like in the question linked to – Kelvin Wayne Jan 29 '17 at 17:25
  • I've looked at that library and emailed the author and you are right. The main issues with the library is that is made for a one-off conversion (not on the fly) and its only for XML->JSON and not the other way around. I'll continue studying it. – Kelvin Wayne Jan 31 '17 at 08:42
  • Is there version for .NET that does XML -> JSON based on XSD? – Nikolay Klimchuk Dec 12 '19 at 14:11