Description
[ copied to eclipselink from stackoverflow: https://stackoverflow.com/questions/79655678/moxy-dynamicjaxbcontext-value-wrapper-and-attribute-prefix ]
I am migrating a use-case from XML -> SaticJAXB -> MongoDocument to XML -> DynamicJAXB -> MongoDocument
To avoid information loss, allowing equivalent XML to be reconstituted later from the JSON/BSON in mongodb, it is necessary to customise the value wrapper (by default "value") and to customise the attribute prefix (by default there is none).
DynamicJAXBContext dynamicContext = DynamicJAXBContextFactory.createContextFromXSD(xmlSchema, entityResolver, classLoader, properties);
JAXBUnmarshaller unmarshaller = dynamicContext.createUnmarshaller();
JAXBElement root = (JAXBElement) unmarshaller.unmarshal(xml);
Having obtained the JAXBElement representing the root element of the XML document I am able recursively to iterate DynamicEntityImpl.PropertyWrapper in order to build up the JSON/BSON document analogous to the original XML.
However, without disambiguation of XML value and attribute names it will not be possible to recreate the XML from JSON/BSON.
I have tried using
unmarshaller.setProperty(UnmarshallerProperties.JSON_VALUE_WRAPPER, "#value");
unmarshaller.setProperty(UnmarshallerProperties.JSON_ATTRIBUTE_PREFIX, "_");
but of course my code is not actually using any of MOXy's JSON abstractions, this is essentially an XML Unmarshaller, so upon reflection I am not surprised that this was unsuccessful.
Perhaps most helpful to me would be the addition of similar properties "XML_VALUE_WRAPPER" and "XML_ATTRIBUTE_PREFIX" to be recognised by the XML parser and which could be set via Map properties when constructing DynamicJAXBContext.
I will be raising several issues against eclipselink MOXy. Most will be feature requests. This one is by far the most critical to my project.