public class TestCustomHashMapConverter implements CustomConverter {
public Object convert(Object destination, Object source, Class<?> destClass, Class<?> sourceClass) {
if (source instanceof TestCustomConverterHashMapObject) {
TestCustomConverterHashMapPrimeObject dest = null;
TestCustomConverterHashMapObject testCustomConverterHashMapObject = (TestCustomConverterHashMapObject) source;
if (destination == null) {
dest = new TestCustomConverterHashMapPrimeObject();
} else {
dest = (TestCustomConverterHashMapPrimeObject) destination;
}
HashMap<Object, BaseTestObject> map = new HashMap<Object, BaseTestObject>();
map.put("object1", testCustomConverterHashMapObject.getTestObject());
map.put("object2", testCustomConverterHashMapObject.getTestObjectPrime());
dest.setTestObjects(map);
return dest;
} else if (source instanceof TestCustomConverterHashMapPrimeObject) {
TestCustomConverterHashMapObject dest = null;
TestCustomConverterHashMapPrimeObject testCustomConverterHashMapPrimeObject = (TestCustomConverterHashMapPrimeObject) source;
if (destination == null) {
dest = new TestCustomConverterHashMapObject();
} else {
dest = (TestCustomConverterHashMapObject) destination;
}
dest.setTestObject((TestObject) testCustomConverterHashMapPrimeObject.getTestObjects().get("object1"));
dest.setTestObjectPrime((TestObjectPrime) testCustomConverterHashMapPrimeObject.getTestObjects().get("object2"));
return dest;
} else {
throw new MappingException("Converter TestCustomHashMapConverter used incorrectly. Arguments passed in were:" + destination
+ " and " + source);
}