My Oracle Support Banner

Problem Deserializing Xmlrefid And Customizing JAXB Unmarshaller (Doc ID 1330790.1)

Last updated on SEPTEMBER 25, 2020

Applies to:

Oracle WebLogic Server - Version 10.3.4 and later
Information in this document applies to any platform.

Symptoms

JAXB types: <CLASSNAME1>, <CLASSNAME2>, <CLASSNAME3>, <CLASSNAME4>

 @XmlRootElement
public class <CLASSNAME1> extends <CLASSNAME3> implements Serializable {
...
public class Country extends <CLASSNAME3> implements Serializable {

 @XmlAccessorType(XmlAccessType.FIELD)
 @XmlRootElement
public class <CLASSNAME3> implements <CLASSNAME4> {

 @XmlID
private String id;

 @XmlIDREF
private <CLASSNAME3> parent;

public interface <CLASSNAME4> {
public void setId(String id);
}
...

<CLASSNAME1>/<CLASSNAME2> extends <CLASSNAME3>, which has a id field, also a parent field.  The parent is another instance of <CLASSNAME3>.

A dummy <CLASSNAME1> instance is initialized like the following:

<CLASSNAME1> city = new <CLASSNAME1>();
...
city.setId(cityId);
...
city.setParent(state);

which the state is:

<CLASSNAME3> state = new <CLASSNAME3>();
...
state.setId("2345678");
...
state.setParent(country);

which the country is:

<CLASSNAME2> country = new <CLASSNAME3>();
...
country.setId("3456789");
...
country.setParent(null);

After the <CLASSNAME1> is marshalled, then unmarshalled, the following output is observed:

code:xxx, createdBy:xx, defaultName:xxxx, lastUpdatedBy:xx, reportName:xxxx, type:CITY, createdDt:<DATE>, lastUpdatedDt:<DATE>, id:123456, inactiveEffectiveDate:<DATE>, parent:null, alternativeNames:xxxx, timeZones:xxxxx utilDate : <DATE>, postalCodes: xxxx, customerGroupRegionCode: xxx, cy : true, defaultPostalCode: xxx, door : true, latitude : xxx, longitude : xxx, opZoneCode : xxx, shippingPoint : true, sqlDate :<DATE>, unLocationCode : null

As can be seen, the parent bit is null.

When using custom IDResolver:

public Callable resolve(final String id, Class targetType) {
final String className=targetType.getCanonicalName();
return new Callable() {
public Object call() {
System.out.println("Id:" + id + ", targetType:" + className);
return createObjectWithId(className, id);
}
};
}

private Object createObjectWithId(String className, String idValue) {
Object object = null;
try {
Class classDefinition = Class.forName(className);
object = classDefinition.newInstance();
((<CLASSNAME4>) object).setId(idValue);
} catch (InstantiationException e) {
System.out.println(e);
} catch (IllegalAccessException e) {
System.out.println(e);
} catch (ClassNotFoundException e) {
System.out.println(e);
}
return object;
}

}

The output is:

code:xxx, createdBy:xx, defaultName:xxxx, lastUpdatedBy:xxx, reportName:xxx, type:xxx, createdDt:<DATE>, lastUpdatedDt:<DATE>, id:123456, inactiveEffectiveDate:<DATE>, parent: [ code:null, createdBy:null, defaultName:null, lastUpdatedBy:null, reportName:null, type:null, createdDt:null, lastUpdatedDt:null, id:2345678, inactiveEffectiveDate:null, parent:null, alternativeNames:null, timeZones:null], alternativeNames:xxx, timeZones:xxx utilDate : <DATE>, postalCodes: xxx, customerGroupRegionCode: xxx, cy : xxx, defaultPostalCode: xxx, door : xx, latitude : xx, longitude : xx, opZoneCode : xx, shippingPoint : xx, sqlDate : <DATE>, unLocationCode : null

Observe that the parent bit is:

[ code:null, createdBy:null, defaultName:null, lastUpdatedBy:null, reportName:null, type:null, createdDt:null, lastUpdatedDt:null, id:2345678, inactiveEffectiveDate:null, parent:null, alternativeNames:null, timeZones:null]

id:2345678 is the state id set earlier.  The rest are null as expected as the IDResolver doesn't set other fields.

However, with JAX-WS web service deployed on WebLogic, there is no way to gain access to JAXB unmashaller, thus cannot set the custom IDResolver.

Changes

 

Cause

To view full details, sign in with your My Oracle Support account.

Don't have a My Oracle Support account? Click to get started!


In this Document
Symptoms
Changes
Cause
Solution
References


My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.