MessageConverterImpl implements MessageConverter { public Object convertToTypedObject(Object source, Type type) throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException, InstantiationException { LOGGER.debug("convertToTypedObject(source = {}, type = {})", source, type); if (type instanceof PrimitiveType) { LOGGER.debug("Type is a Primitive Type"); return source; } else if (type instanceof ListType) { LOGGER.debug("Type is a List Type"); ListType listType = (ListType) type; Object[] components = (Object[]) source; List<Object> list = new ArrayList<Object>(); for (Object component : components) { list.add(convertToTypedObject(component, listType.getElementType())); } return list; } else if (type instanceof RecordType) { LOGGER.debug("Type is a Record(Map) Type"); RecordType recordType = (RecordType) type; Class<?> recordClass = classLoader.loadClass(recordType); Map<String, Object> map = new HashMap<String, Object>(); for (Entry<String, Type> entry : recordType.getFieldTypes() .entrySet()) { Object fieldValue = recordClass.getField(entry.getKey()).get( source); map.put(entry.getKey(), convertToTypedObject(fieldValue, entry.getValue())); } return map; } LOGGER.error("Type is invalid"); throw new InstantiationException(); } MessageConverterImpl(EgovWebServiceClassLoader classLoader); @SuppressWarnings("unchecked") Object convertToValueObject(Object source, Type type); Object convertToTypedObject(Object source, Type type);  }
@SuppressWarnings("unchecked") @Test public void testConvertToTypedObject() throws Exception { Object object = messageConverter.convertToTypedObject(valueObject, recordType); assertNotNull(object); assertTrue(object instanceof Map); Map<String, Object> typedObject = (Map<String, Object>) object; assertEquals(valueObject.booleanValue, typedObject.get("booleanValue")); assertEquals(valueObject.byteValue, typedObject.get("byteValue")); assertEquals(valueObject.shortValue, typedObject.get("shortValue")); assertEquals(valueObject.intValue, typedObject.get("intValue")); assertEquals(valueObject.longValue, typedObject.get("longValue")); assertEquals(valueObject.bigIntegerValue, typedObject.get("bigIntegerValue")); assertEquals(valueObject.floatValue, typedObject.get("floatValue")); assertEquals(valueObject.doubleValue, typedObject.get("doubleValue")); assertEquals(valueObject.bigDecimalValue, typedObject.get("bigDecimalValue")); assertEquals(valueObject.stringValue, typedObject.get("stringValue")); assertEquals(valueObject.calendarValue, typedObject.get("calendarValue")); Person[] personArray = valueObject.personList; object = typedObject.get("personList"); assertNotNull(object); assertTrue(object instanceof List); List<Object> personList = (List<Object>) object; assertEquals(personArray.length, personList.size()); for (int i = 0; i < personArray.length; i++) { Person person = personArray[i]; object = personList.get(i); assertNotNull(object); assertTrue(object instanceof Map); Map<String, Object> personMap = (Map<String, Object>) object; assertEquals(person.no, personMap.get("no")); assertEquals(person.name, personMap.get("name")); } }