@Test public void testImmutableMapJsonCodec() { JsonCodec<Map<String, ImmutablePerson>> jsonCodec = mapJsonCodec(String.class, ImmutablePerson.class); ImmutablePerson.validatePersonMapJsonCodec(jsonCodec); }
public static <K, V> JsonCodec<Map<K, V>> mapJsonCodec(Class<K> keyType, Class<V> valueType) { requireNonNull(keyType, "keyType is null"); requireNonNull(valueType, "valueType is null"); Type mapType = new TypeToken<Map<K, V>>() {} .where(new TypeParameter<K>() {}, keyType) .where(new TypeParameter<V>() {}, valueType) .getType(); return new JsonCodec<>(OBJECT_MAPPER_SUPPLIER.get(), mapType); }
JsonCodec { public static <K, V> JsonCodec<Map<K, V>> mapJsonCodec(Class<K> keyType, Class<V> valueType) { requireNonNull(keyType, "keyType is null"); requireNonNull(valueType, "valueType is null"); Type mapType = new TypeToken<Map<K, V>>() {} .where(new TypeParameter<K>() {}, keyType) .where(new TypeParameter<V>() {}, valueType) .getType(); return new JsonCodec<>(OBJECT_MAPPER_SUPPLIER.get(), mapType); } }
JsonCodec { public static <K, V> JsonCodec<Map<K, V>> mapJsonCodec(Class<K> keyType, Class<V> valueType) { requireNonNull(keyType, "keyType is null"); requireNonNull(valueType, "valueType is null"); Type mapType = new TypeToken<Map<K, V>>() {} .where(new TypeParameter<K>() {}, keyType) .where(new TypeParameter<V>() {}, valueType) .getType(); return new JsonCodec<>(OBJECT_MAPPER_SUPPLIER.get(), mapType); } JsonCodec(ObjectMapper mapper, Type type); }
JsonCodec { public static <K, V> JsonCodec<Map<K, V>> mapJsonCodec(Class<K> keyType, Class<V> valueType) { requireNonNull(keyType, "keyType is null"); requireNonNull(valueType, "valueType is null"); Type mapType = new TypeToken<Map<K, V>>() {} .where(new TypeParameter<K>() {}, keyType) .where(new TypeParameter<V>() {}, valueType) .getType(); return new JsonCodec<>(OBJECT_MAPPER_SUPPLIER.get(), mapType); } JsonCodec(ObjectMapper mapper, Type type); static JsonCodec<T> jsonCodec(Class<T> type); static JsonCodec<T> jsonCodec(TypeToken<T> type); static JsonCodec<List<T>> listJsonCodec(Class<T> type); static JsonCodec<List<T>> listJsonCodec(JsonCodec<T> type); static JsonCodec<Map<K, V>> mapJsonCodec(Class<K> keyType, Class<V> valueType); static JsonCodec<Map<K, V>> mapJsonCodec(Class<K> keyType, JsonCodec<V> valueType); JsonCodec<T> withoutPretty(); Type getType(); T fromJson(String json); String toJson(T instance); Optional<String> toJsonWithLengthLimit(T instance, int lengthLimit); T fromJson(byte[] json); byte[] toJsonBytes(T instance); }
JsonCodec { public static <K, V> JsonCodec<Map<K, V>> mapJsonCodec(Class<K> keyType, Class<V> valueType) { requireNonNull(keyType, "keyType is null"); requireNonNull(valueType, "valueType is null"); Type mapType = new TypeToken<Map<K, V>>() {} .where(new TypeParameter<K>() {}, keyType) .where(new TypeParameter<V>() {}, valueType) .getType(); return new JsonCodec<>(OBJECT_MAPPER_SUPPLIER.get(), mapType); } JsonCodec(ObjectMapper mapper, Type type); static JsonCodec<T> jsonCodec(Class<T> type); static JsonCodec<T> jsonCodec(TypeToken<T> type); static JsonCodec<List<T>> listJsonCodec(Class<T> type); static JsonCodec<List<T>> listJsonCodec(JsonCodec<T> type); static JsonCodec<Map<K, V>> mapJsonCodec(Class<K> keyType, Class<V> valueType); static JsonCodec<Map<K, V>> mapJsonCodec(Class<K> keyType, JsonCodec<V> valueType); JsonCodec<T> withoutPretty(); Type getType(); T fromJson(String json); String toJson(T instance); Optional<String> toJsonWithLengthLimit(T instance, int lengthLimit); T fromJson(byte[] json); byte[] toJsonBytes(T instance);  }