Community
Participate
Working Groups
Starting at line 350 of XMLAnyObjectMapping: if (referenceDescriptor != null) { ObjectBuilder builder = referenceDescriptor.getObjectBuilder(); objectValue = builder.buildObject(query, nestedRecord, joinManager); Object updated = ((XMLDescriptor) referenceDescriptor).wrapObjectInXMLRoot(objectValue, next.getNamespaceURI(), next.getLocalName(), next.getPrefix(), false); if(getConverter() != null) { updated = getConverter().convertDataValueToObjectValue(objectValue, session, record.getUnmarshaller()); } return updated; } else if ((referenceDescriptor != null) && (getKeepAsElementPolicy() != UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT)) { return buildObjectAndWrapInXMLRoot(referenceDescriptor, getConverter(), query, record, nestedRecord, joinManager, session, next, null, null); } else { The else if condition will never be met since the initial if condition addressed referenceDescriptor != null
Created attachment 184988 [details] Proposed fix
Created attachment 184997 [details] Supporting tests
Created attachment 185163 [details] Proposed fix
Created attachment 185164 [details] Supporting tests
The fix involves more than just removing the unreachable code; the logic in that block needs to be reworked. This DOM platform use case involves unmapped Elements whose mappings are set to use XMLRoot. There are three cases we need to handle here: 1) KEEP_ALL_AS_ELEMENT or (referenceDescriptor == null && KEEP_UNKNOWN_AS_ELEMENT): - in this case we want to return the element - the returned element will be wrapped in a XMLRoot if there is no reference descriptor - the returned element may/may not be wrapped in an XMLRoot if there is a reference descriptor, as the descriptor decides if the value should be wrapped or not (as is done in SAX) 2) If criteria for 1) above is not met and there is a reference descriptor: - the reference descriptor is used to build the object to return - the returned object may/may not be wrapped in an XMLRoot, as the descriptor decides if the value should be wrapped or not (as is done in SAX) 3) If criteria is not met for either 1) or 2) above: - if the first child of the unknown element is TEXT, and contains a non-empty String, the String value will be wrapped in an XMLRoot - if the schema type is known and maps to an XML type (i.e. boolean, dateTime, etc.), the String value will be converted to the XML type before being wrapped in an XMLRoot
The logic change will apply to the collection use case as well.
Reviewed by: matt.macivor@oracle.com Tests: all unit tests pass as expected; oxm.mappings.anyobject.withoutgroupingelement.AnyObjectKeepAllAsElementTestCases Revision: 8710
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink