|
@@ -1,6 +1,8 @@
|
|
|
package org.hswebframework.web.starter.jackson;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import lombok.Getter;
|
|
|
+import lombok.Setter;
|
|
|
import lombok.SneakyThrows;
|
|
|
import org.hswebframework.web.api.crud.entity.EntityFactory;
|
|
|
import org.hswebframework.web.api.crud.entity.QueryParamEntity;
|
|
@@ -17,6 +19,7 @@ import org.springframework.util.MimeType;
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
@@ -28,7 +31,7 @@ public class CustomJackson2JsonDecoderTest {
|
|
|
|
|
|
MapperEntityFactory entityFactory = new MapperEntityFactory();
|
|
|
|
|
|
- entityFactory.addMapping(QueryParamEntity.class,MapperEntityFactory.defaultMapper(CustomQueryParamEntity.class));
|
|
|
+ entityFactory.addMapping(QueryParamEntity.class, MapperEntityFactory.defaultMapper(CustomQueryParamEntity.class));
|
|
|
|
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
@@ -46,6 +49,30 @@ public class CustomJackson2JsonDecoderTest {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ @SneakyThrows
|
|
|
+ public void testDecodeList() {
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
+ CustomJackson2JsonDecoder decoder = new CustomJackson2JsonDecoder(new MapperEntityFactory(), mapper);
|
|
|
+
|
|
|
+ ResolvableType type = ResolvableType.forClassWithGenerics(List.class, MyEntity.class);
|
|
|
+ DataBuffer buffer = new DefaultDataBufferFactory().wrap("[{\"id\":\"test\"}]".getBytes());
|
|
|
+
|
|
|
+ Object object = decoder.decode(buffer, type, MediaType.APPLICATION_JSON, Collections.emptyMap());
|
|
|
+
|
|
|
+ assertTrue(object instanceof List);
|
|
|
+ assertTrue(((List<?>) object).size() > 0);
|
|
|
+ assertTrue(((List<?>) object).get(0) instanceof MyEntity);
|
|
|
+ assertEquals(((MyEntity) ((List<?>) object).get(0)).getId(), "test");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Getter
|
|
|
+ @Setter
|
|
|
+ public static class MyEntity {
|
|
|
+ private String id;
|
|
|
+ }
|
|
|
+
|
|
|
public static class CustomQueryParamEntity extends QueryParamEntity {
|
|
|
|
|
|
}
|