Converts UBL documents to / from XML / JSON formats with fast javax XML/JSON streaming.
Convert from UBL XML to JSON example (Kotlin):
val xmlFile = File("/path/to/file.xml")
val xmlInputStream = xmlFile.inputStream()
val jsonOutputStream = ByteArrayOutputStream()
val converter = UBLToJsonFormatConverterFactory(prettyPrint = true, version = UBLJsonVersion.V2)
.createConverter(xmlInputStream, jsonOutputStream)
converter.convert()
val convertedJsonString = jsonOutputStream.toString(Charsets.UTF_8.name())
println(convertedJsonString)
- Generate UBL 2.1 JSON Alternative Representation from XML for both version 1.0 and version 2.0.
- Compact or pretty print output (with javax.json.stream.JsonGenerator).
- Quick (uses XML and JSON streaming API).
It does not use schema for output generation, it uses some heuristics for determining types and name mapping. Especially for JSON V1 this may fail. That being said, it has extensive tests that covers all examples in the UBL standard, so this should provide a certain level of confidence.