diff --git a/Integration/org.egovframe.rte.itl.webservice/src/main/java/org/egovframe/rte/itl/webservice/service/impl/MessageConverterImpl.java b/Integration/org.egovframe.rte.itl.webservice/src/main/java/org/egovframe/rte/itl/webservice/service/impl/MessageConverterImpl.java index 2731e340..159dba4b 100755 --- a/Integration/org.egovframe.rte.itl.webservice/src/main/java/org/egovframe/rte/itl/webservice/service/impl/MessageConverterImpl.java +++ b/Integration/org.egovframe.rte.itl.webservice/src/main/java/org/egovframe/rte/itl/webservice/service/impl/MessageConverterImpl.java @@ -116,6 +116,11 @@ public Object convertToTypedObject(Object source, Type type) throws ClassNotFoun return source; } else if (type instanceof ListType) { LOGGER.debug("### MessageConverterImpl convertToTypedObject() : Type is a List Type"); + // 변환 대상 Value Object의 List 필드가 null이면 역참조 전에 null을 그대로 반환한다. + // 타입 체계가 null을 유효 값으로 허용한다. + if (source == null) { + return null; + } ListType listType = (ListType) type; Object[] components = (Object[]) source; List list = new ArrayList(); @@ -125,6 +130,11 @@ public Object convertToTypedObject(Object source, Type type) throws ClassNotFoun return list; } else if (type instanceof RecordType) { LOGGER.debug("### MessageConverterImpl convertToTypedObject() : Type is a Record(Map) Type"); + // 변환 대상 Value Object의 Record 필드가 null이면 역참조 전에 null을 그대로 반환한다. + // 타입 체계가 null을 유효 값으로 허용한다. + if (source == null) { + return null; + } RecordType recordType = (RecordType) type; Class recordClass = classLoader.loadClass(recordType); Map map = new HashMap(); diff --git a/Integration/org.egovframe.rte.itl.webservice/src/test/java/org/egovframe/rte/itl/webservice/service/impl/MessageConverterImplTest.java b/Integration/org.egovframe.rte.itl.webservice/src/test/java/org/egovframe/rte/itl/webservice/service/impl/MessageConverterImplTest.java index 78dafd0b..5ca16f6d 100755 --- a/Integration/org.egovframe.rte.itl.webservice/src/test/java/org/egovframe/rte/itl/webservice/service/impl/MessageConverterImplTest.java +++ b/Integration/org.egovframe.rte.itl.webservice/src/test/java/org/egovframe/rte/itl/webservice/service/impl/MessageConverterImplTest.java @@ -267,6 +267,39 @@ public void testConvertToValueObjectWithNullRecordSource() throws Exception { // null 역참조(NPE) 없이 null을 반환해야 한다. assertNull(messageConverter.convertToValueObject(null, recordType)); } + + @Test + public void testConvertToTypedObjectWithNullListSource() throws Exception { + // 변환 대상 Value Object의 List 필드가 null인 경우이다. + // null 역참조(NPE) 없이 null을 반환해야 한다. + assertNull(messageConverter.convertToTypedObject(null, personListType)); + } + + @Test + public void testConvertToTypedObjectWithNullRecordSource() throws Exception { + // 변환 대상 Value Object의 Record 필드가 null인 경우이다. + // null 역참조(NPE) 없이 null을 반환해야 한다. + assertNull(messageConverter.convertToTypedObject(null, personRecordType)); + } + + @Test + public void testConvertToTypedObjectWithNullListField() throws Exception { + // List 필드가 null인 Value Object도 나머지 필드는 정상적으로 변환되어야 한다. + ValueObject source = new ValueObject() { + { + stringValue = "String"; + personList = null; + } + }; + + Object object = messageConverter.convertToTypedObject(source, recordType); + assertInstanceOf(Map.class, object); + + Map typedObject = (Map) object; + assertEquals("String", typedObject.get("stringValue")); + assertTrue(typedObject.containsKey("personList")); + assertNull(typedObject.get("personList")); + } } class ValueObject {