Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> list = new ArrayList<Object>();
Expand All @@ -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<String, Object> map = new HashMap<String, Object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> typedObject = (Map<String, Object>) object;
assertEquals("String", typedObject.get("stringValue"));
assertTrue(typedObject.containsKey("personList"));
assertNull(typedObject.get("personList"));
}
}

class ValueObject {
Expand Down