|
| 1 | +package org.jooby.internal.apitool; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 4 | +import com.google.inject.util.Types; |
| 5 | +import org.junit.Test; |
| 6 | + |
| 7 | +import java.lang.reflect.ParameterizedType; |
| 8 | +import java.lang.reflect.Type; |
| 9 | +import java.util.UUID; |
| 10 | + |
| 11 | +import static org.junit.Assert.assertEquals; |
| 12 | + |
| 13 | +public class ComplexMapTypesTest { |
| 14 | + |
| 15 | + public static class TypeWrapper { |
| 16 | + private Type type; |
| 17 | + |
| 18 | + public Type getType() { |
| 19 | + return type; |
| 20 | + } |
| 21 | + |
| 22 | + public void setType(Type type) { |
| 23 | + this.type = type; |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + @Test |
| 28 | + public void shouldDeserializeMapWithListProperly() throws Exception { |
| 29 | + ObjectMapper mapper = BytecodeRouteParser.mapper; |
| 30 | + TypeWrapper expected = new TypeWrapper(); |
| 31 | + ParameterizedType type = Types.mapOf(UUID.class, Types.listOf(Integer.class)); |
| 32 | + expected.setType(type); |
| 33 | + String json = mapper.writeValueAsString(expected); |
| 34 | + TypeWrapper actual = mapper.readValue(json, TypeWrapper.class); |
| 35 | + assertEquals(expected.getType(), actual.getType()); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + public void shouldDeserializeMapWithMapWithListProperly() throws Exception { |
| 40 | + ObjectMapper mapper = BytecodeRouteParser.mapper; |
| 41 | + TypeWrapper expected = new TypeWrapper(); |
| 42 | + ParameterizedType type = Types.mapOf(UUID.class, Types.mapOf(UUID.class, Types.listOf(Integer.class))); |
| 43 | + expected.setType(type); |
| 44 | + String json = mapper.writeValueAsString(expected); |
| 45 | + TypeWrapper actual = mapper.readValue(json, TypeWrapper.class); |
| 46 | + assertEquals(expected.getType(), actual.getType()); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void shouldDeserializeListWithMapWithListProperly() throws Exception { |
| 51 | + ObjectMapper mapper = BytecodeRouteParser.mapper; |
| 52 | + TypeWrapper expected = new TypeWrapper(); |
| 53 | + ParameterizedType type = Types.listOf(Types.mapOf(UUID.class, Types.mapOf(UUID.class, Types.listOf(Integer.class)))); |
| 54 | + expected.setType(type); |
| 55 | + String json = mapper.writeValueAsString(expected); |
| 56 | + TypeWrapper actual = mapper.readValue(json, TypeWrapper.class); |
| 57 | + assertEquals(expected.getType(), actual.getType()); |
| 58 | + } |
| 59 | + |
| 60 | +} |
0 commit comments