Skip to content
Open
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 @@ -75,6 +75,11 @@ public Object convertToValueObject(Object source, Type type) throws ClassNotFoun
return source;
} else if (type instanceof ListType) {
LOGGER.debug("### MessageConverterImpl convertToValueObject() : Type is a List Type");
// 메시지 body에서 List 필드가 생략되면 source가 null로 전달된다.
// 타입 체계가 null을 유효 값으로 허용하므로, 역참조 전에 null을 그대로 반환한다.
if (source == null) {
return null;
}
ListType listType = (ListType) type;
Object[] components = ((Collection<?>) source).toArray();
Class<?> arrayClass = classLoader.loadClass(listType);
Expand All @@ -85,6 +90,11 @@ public Object convertToValueObject(Object source, Type type) throws ClassNotFoun
return array;
} else if (type instanceof RecordType) {
LOGGER.debug("### MessageConverterImpl convertToValueObject() : Type is a Record(Map) Type");
// 메시지 body에서 Record 필드가 생략되면 source가 null로 전달된다.
// 타입 체계가 null을 유효 값으로 허용하므로, 역참조 전에 null을 그대로 반환한다.
if (source == null) {
return null;
}
RecordType recordType = (RecordType) type;
Map<String, Object> map = (Map<String, Object>) source;
Class<?> recordClass = classLoader.loadClass(recordType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,20 @@ public void testConvertToTypedObject() throws Exception {
assertEquals(person.name, personMap.get("name"));
}
}

@Test
public void testConvertToValueObjectWithNullListSource() throws Exception {
// 메시지 body에서 List 필드가 생략되면 source가 null로 전달된다.
// null 역참조(NPE) 없이 null을 반환해야 한다.
assertNull(messageConverter.convertToValueObject(null, personListType));
}

@Test
public void testConvertToValueObjectWithNullRecordSource() throws Exception {
// 메시지 body에서 Record 필드가 생략되면 source가 null로 전달된다.
// null 역참조(NPE) 없이 null을 반환해야 한다.
assertNull(messageConverter.convertToValueObject(null, recordType));
}
}

class ValueObject {
Expand Down