MappingJackson2MessageConverter uses generic type

Issue: SPR-16252
This commit is contained in:
Rossen Stoyanchev
2017-12-12 22:32:33 -05:00
parent f05175586e
commit 583201b02c
2 changed files with 42 additions and 3 deletions

View File

@@ -21,6 +21,7 @@ import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonView;
@@ -33,8 +34,16 @@ import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.util.MimeType;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/**
* Test fixture for {@link org.springframework.messaging.converter.MappingJackson2MessageConverter}.
@@ -127,6 +136,20 @@ public class MappingJackson2MessageConverterTests {
assertEquals("string", myBean.getString());
}
@Test // SPR-16252
public void fromMessageToList() throws Exception {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
String payload = "[1, 2, 3, 4, 5, 6, 7, 8, 9]";
Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build();
Method method = getClass().getDeclaredMethod("handleList", List.class);
MethodParameter param = new MethodParameter(method, 0);
Object actual = converter.fromMessage(message, List.class, param);
assertNotNull(actual);
assertEquals(Arrays.asList(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L), actual);
}
@Test
public void toMessage() throws Exception {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
@@ -217,6 +240,8 @@ public class MappingJackson2MessageConverterTests {
public void jsonViewPayload(@JsonView(MyJacksonView2.class) JacksonViewBean payload) {
}
void handleList(List<Long> payload) {}
public static class MyBean {