Description
[ copied to eclipselink from stackoverflow: https://stackoverflow.com/questions/79658708/moxy-dynamicjaxbcontext-control-over-href-expansion ]
I am migrating a use-case from XML -> SaticJAXB -> MongoDocument to XML -> DynamicJAXB -> MongoDocument
DynamicJAXBContext dynamicContext = DynamicJAXBContextFactory.createContextFromXSD(xmlSchema, entityResolver, classLoader, properties);
JAXBUnmarshaller unmarshaller = dynamicContext.createUnmarshaller();
JAXBElement root = (JAXBElement) unmarshaller.unmarshal(xml);
Given a snipped of XML Schema below
<xsd:complexType name="ContactReference">
<xsd:attribute name="href" type="xsd:IDREF" use="required">
<xsd:annotation>
<xsd:documentation>A reference to the @id value of contact/NamedPerson detailed elsewhere in this document.</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
And a corresponding snipped of inbound XML containing href:
<clientContact>
<accountOfficer id="_1_39" type="RelationshipManager">
<identifier name="Name">Robin Roos</identifier>
<emailAddress>[email protected]</emailAddress>
</accountOfficer>
<primaryAccountOfficer href="_1_39"/>
</clientContact>
The href is resolved as being an instance of accountOfficer.
I will use JSON/BSON representation below, but of course the MOXy code is not generating JSON/BSON (it is my backend which does so). JSON is a convenient way to represent what in MOXy terms would be an in-memory graph of DynamicEntity.
What I actually receive from MOXy is:
"clientContact": {
"accountOfficer": [
{
"identifier": [
{
"name": "Name",
"value": "Robin Roos"
}
],
"emailAddress": "[email protected]",
"id": "_1_39",
"type": "RelationshipManager"
}
],
"primaryAccountOfficer": {
"href": {
"identifier": [
{
"name": "Name",
"value": "Robin Roos"
}
],
"emailAddress": "[email protected]",
"id": "_1_39",
"type": "RelationshipManager"
}
}
}
}
What I hope to achieve by disabling href expansion is:
"clientContact": {
"accountOfficer": [
{
"identifier": [
{
"name": "Name",
"value": "Robin Roos"
}
],
"emailAddress": "[email protected]",
"id": "_1_39",
"type": "RelationshipManager"
}
],
"primaryAccountOfficer": {
"href": "_1_39"
}
}
}
From my side this problem is tractable. My present work-around is to assume "href" always represents "href expansion": to observe the "href" DynamicElement and substitute its entire value with just the String value of the "id" property contained within its DynamicElementImpl.propertiesMap.
My preference, however, is to avail of a configuration switch by which href expansion can be disabled, thus no longer making assumptions based on the property names observed downstream from MOXy.