@SuppressWarnings("unchecked") @Test public void testConvertToValueObject() throws Exception { Object object = messageConverter.convertToValueObject(typedObject, recordType); assertNotNull(object); assertTrue(object instanceof ValueObject); ValueObject valueObject = (ValueObject) object; assertEquals(typedObject.get("booleanValue"), valueObject.booleanValue); assertEquals(typedObject.get("byteValue"), valueObject.byteValue); assertEquals(typedObject.get("shortValue"), valueObject.shortValue); assertEquals(typedObject.get("intValue"), valueObject.intValue); assertEquals(typedObject.get("longValue"), valueObject.longValue); assertEquals(typedObject.get("bigIntegerValue"), valueObject.bigIntegerValue); assertEquals(typedObject.get("floatValue"), valueObject.floatValue); assertEquals(typedObject.get("doubleValue"), valueObject.doubleValue); assertEquals(typedObject.get("bigDecimalValue"), valueObject.bigDecimalValue); assertEquals(typedObject.get("stringValue"), valueObject.stringValue); assertEquals(typedObject.get("calendarValue"), valueObject.calendarValue); Person[] personArray = valueObject.personList; assertNotNull(personArray); assertEquals(personList.size(), personArray.length); for (int i = 0; i < personList.size(); i++) { Map<String, Object> personMap = (Map<String, Object>) personList.get(i); Person person = personArray[i]; assertEquals(personMap.get("no"), person.no); assertEquals(personMap.get("name"), person.name); } }
@SuppressWarnings("unchecked") public Object convertToValueObject(Object source, Type type) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchFieldException { LOGGER.debug("convertToValueObject(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 = ((Collection<?>) source).toArray(); Class<?> arrayClass = classLoader.loadClass(listType); Object array = Array.newInstance(arrayClass.getComponentType(), components.length); for (int i = 0; i < components.length; i++) { Array.set( array, i, convertToValueObject(components[i], listType.getElementType())); } return array; } else if (type instanceof RecordType) { LOGGER.debug("Type is a Record(Map) Type"); RecordType recordType = (RecordType) type; Map<String, Object> map = (Map<String, Object>) source; Class<?> recordClass = classLoader.loadClass(recordType); Object record = recordClass.newInstance(); for (Entry<String, Object> entry : map.entrySet()) { Object fieldValue = convertToValueObject(entry.getValue(), recordType.getFieldType(entry.getKey())); recordClass.getField(entry.getKey()).set(record, fieldValue); } return record; } LOGGER.error("Type is invalid"); throw new InstantiationException(); }
MessageConverterImpl implements MessageConverter { @SuppressWarnings("unchecked") public Object convertToValueObject(Object source, Type type) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchFieldException { LOGGER.debug("convertToValueObject(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 = ((Collection<?>) source).toArray(); Class<?> arrayClass = classLoader.loadClass(listType); Object array = Array.newInstance(arrayClass.getComponentType(), components.length); for (int i = 0; i < components.length; i++) { Array.set( array, i, convertToValueObject(components[i], listType.getElementType())); } return array; } else if (type instanceof RecordType) { LOGGER.debug("Type is a Record(Map) Type"); RecordType recordType = (RecordType) type; Map<String, Object> map = (Map<String, Object>) source; Class<?> recordClass = classLoader.loadClass(recordType); Object record = recordClass.newInstance(); for (Entry<String, Object> entry : map.entrySet()) { Object fieldValue = convertToValueObject(entry.getValue(), recordType.getFieldType(entry.getKey())); recordClass.getField(entry.getKey()).set(record, fieldValue); } return record; } LOGGER.error("Type is invalid"); throw new InstantiationException(); } }
MessageConverterImpl implements MessageConverter { @SuppressWarnings("unchecked") public Object convertToValueObject(Object source, Type type) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchFieldException { LOGGER.debug("convertToValueObject(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 = ((Collection<?>) source).toArray(); Class<?> arrayClass = classLoader.loadClass(listType); Object array = Array.newInstance(arrayClass.getComponentType(), components.length); for (int i = 0; i < components.length; i++) { Array.set( array, i, convertToValueObject(components[i], listType.getElementType())); } return array; } else if (type instanceof RecordType) { LOGGER.debug("Type is a Record(Map) Type"); RecordType recordType = (RecordType) type; Map<String, Object> map = (Map<String, Object>) source; Class<?> recordClass = classLoader.loadClass(recordType); Object record = recordClass.newInstance(); for (Entry<String, Object> entry : map.entrySet()) { Object fieldValue = convertToValueObject(entry.getValue(), recordType.getFieldType(entry.getKey())); recordClass.getField(entry.getKey()).set(record, fieldValue); } return record; } LOGGER.error("Type is invalid"); throw new InstantiationException(); } MessageConverterImpl(EgovWebServiceClassLoader classLoader); }
MessageConverterImpl implements MessageConverter { @SuppressWarnings("unchecked") public Object convertToValueObject(Object source, Type type) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchFieldException { LOGGER.debug("convertToValueObject(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 = ((Collection<?>) source).toArray(); Class<?> arrayClass = classLoader.loadClass(listType); Object array = Array.newInstance(arrayClass.getComponentType(), components.length); for (int i = 0; i < components.length; i++) { Array.set( array, i, convertToValueObject(components[i], listType.getElementType())); } return array; } else if (type instanceof RecordType) { LOGGER.debug("Type is a Record(Map) Type"); RecordType recordType = (RecordType) type; Map<String, Object> map = (Map<String, Object>) source; Class<?> recordClass = classLoader.loadClass(recordType); Object record = recordClass.newInstance(); for (Entry<String, Object> entry : map.entrySet()) { Object fieldValue = convertToValueObject(entry.getValue(), recordType.getFieldType(entry.getKey())); recordClass.getField(entry.getKey()).set(record, fieldValue); } return record; } 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); }
MessageConverterImpl implements MessageConverter { @SuppressWarnings("unchecked") public Object convertToValueObject(Object source, Type type) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchFieldException { LOGGER.debug("convertToValueObject(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 = ((Collection<?>) source).toArray(); Class<?> arrayClass = classLoader.loadClass(listType); Object array = Array.newInstance(arrayClass.getComponentType(), components.length); for (int i = 0; i < components.length; i++) { Array.set( array, i, convertToValueObject(components[i], listType.getElementType())); } return array; } else if (type instanceof RecordType) { LOGGER.debug("Type is a Record(Map) Type"); RecordType recordType = (RecordType) type; Map<String, Object> map = (Map<String, Object>) source; Class<?> recordClass = classLoader.loadClass(recordType); Object record = recordClass.newInstance(); for (Entry<String, Object> entry : map.entrySet()) { Object fieldValue = convertToValueObject(entry.getValue(), recordType.getFieldType(entry.getKey())); recordClass.getField(entry.getKey()).set(record, fieldValue); } return record; } 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);  }