CustomMap { public V put(final K key, final V value) { return delegateMap.put(key, value); } CustomMap(final ToBytesSerialiser<? super K> keySerialiser, final ToBytesSerialiser<? super V> valueSerialiser); @JsonCreator  CustomMap(@JsonProperty("keySerialiser") final ToBytesSerialiser<? super K> keySerialiser, @JsonProperty("valueSerialiser") final ToBytesSerialiser<? super V> valueSerialiser, @JsonProperty("jsonStorage") final HashSet<Pair<K, V>> interimPairs);  CustomMap(final ToBytesSerialiser<? super K> keySerialiser, final ToBytesSerialiser<? super V> valueSerialiser, final Map<K, V> storageMap); @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "class") ToBytesSerialiser<? super K> getKeySerialiser(); @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "class") ToBytesSerialiser<? super V> getValueSerialiser(); @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_OBJECT, property = "class") HashSet<Pair<K, V>> getJsonStorage(); @JsonIgnore HashMap<K, V> getMap(); int size(); @JsonIgnore boolean isEmpty(); V get(final Object key); boolean containsKey(final Object key); V put(final K key, final V value); void putAll(final Map<? extends K, ? extends V> m); V remove(final Object key); void clear(); boolean containsValue(final Object value); Set<K> keySet(); Collection<V> values(); Set<Map.Entry<K, V>> entrySet(); V getOrDefault(final Object key, final V defaultValue); V putIfAbsent(final K key, final V value); boolean remove(final Object key, final Object value); boolean replace(final K key, final V oldValue, final V newValue); V replace(final K key, final V value); V computeIfAbsent(final K key, final Function<? super K, ? extends V> mappingFunction); V computeIfPresent(final K key, final BiFunction<? super K, ? super V, ? extends V> remappingFunction); V compute(final K key, final BiFunction<? super K, ? super V, ? extends V> remappingFunction); V merge(final K key, final V value, final BiFunction<? super V, ? super V, ? extends V> remappingFunction); void forEach(final BiConsumer<? super K, ? super V> action); void replaceAll(final BiFunction<? super K, ? super V, ? extends V> function); @Override boolean equals(final Object obj); @Override int hashCode(); @Override String toString();  }
@Test public void shouldJSONSerialiseStringInteger() throws IOException { final CustomMap<String, Integer> expectedMap = new CustomMap<>(new StringSerialiser(), new IntegerSerialiser()); expectedMap.put("one", 1111); expectedMap.put("two", 2222); final String expectedJson = jsonFromFile("custom-map01.json"); final byte[] serialise = JSONSerialiser.serialise(expectedMap, true); final CustomMap jsonMap = JSONSerialiser.deserialise(expectedJson, CustomMap.class); final CustomMap deserialiseMap = JSONSerialiser.deserialise(serialise, CustomMap.class); assertEquals(jsonMap, deserialiseMap, "The expected map from Json doesn't match"); assertEquals(expectedMap, deserialiseMap, "The expected map doesn't match"); }
@Test public void shouldJSONSerialiseBigIntString() throws IOException { final CustomMap<TreeSet<String>, Double> expectedMap = new CustomMap<>(new TreeSetStringSerialiser(), new DoubleSerialiser()); final TreeSet<String> key1 = new TreeSet<>(); key1.add("k1"); key1.add("k2"); expectedMap.put(key1, 11.11); final TreeSet<String> key2 = new TreeSet<>(); key2.add("k3"); key2.add("k4"); expectedMap.put(key2, 22.22); final String expectedJson = jsonFromFile("custom-map02.json"); final byte[] serialise = JSONSerialiser.serialise(expectedMap, true); final CustomMap jsonMap = JSONSerialiser.deserialise(expectedJson, CustomMap.class); final CustomMap deserialiseMap = JSONSerialiser.deserialise(serialise, CustomMap.class); assertEquals(jsonMap, deserialiseMap, "The expected map from Json doesn't match"); assertEquals(expectedMap, deserialiseMap, "The expected map doesn't match"); }
@Test public void shouldJSONSerialiseStringMap() throws IOException { final MapSerialiser mapSerialiser = new MapSerialiser(); mapSerialiser.setValueSerialiser(new StringSerialiser()); mapSerialiser.setKeySerialiser(new StringSerialiser()); final CustomMap<String, HashMap> expectedMap = new CustomMap<>(new StringSerialiser(), mapSerialiser); final HashMap<String, String> innerMap1 = new HashMap<>(); innerMap1.put("innerKeyOne", "innerValue1"); final HashMap<String, String> innerMap2 = new HashMap<>(); innerMap2.put("innerKeyTwo", "innerValue2"); expectedMap.put("innerOne", innerMap1); expectedMap.put("innerTwo", innerMap2); final String expectedJson = jsonFromFile("custom-map03.json"); final byte[] serialise = JSONSerialiser.serialise(expectedMap, true); final CustomMap jsonMap = JSONSerialiser.deserialise(expectedJson, CustomMap.class); final CustomMap deserialiseMap = JSONSerialiser.deserialise(serialise, CustomMap.class); assertEquals(jsonMap, deserialiseMap, "The expected map from Json doesn't match"); assertEquals(expectedMap, deserialiseMap, "The expected map doesn't match"); }
@Test public void shouldJSONSerialiseFloatRDM() throws IOException { System.setProperty(JSONSerialiser.JSON_SERIALISER_MODULES, BitmapJsonModules.class.getCanonicalName()); final RBMBackedTimestampSet timestampSet1 = new RBMBackedTimestampSet.Builder() .timeBucket(CommonTimeUtil.TimeBucket.MINUTE) .timestamps(Lists.newArrayList(Instant.ofEpochSecond(11))) .build(); final RBMBackedTimestampSet timestampSet2 = new RBMBackedTimestampSet.Builder() .timeBucket(CommonTimeUtil.TimeBucket.HOUR) .timestamps(Lists.newArrayList(Instant.ofEpochSecond(222222))) .build(); final CustomMap<Float, RBMBackedTimestampSet> expectedMap = new CustomMap<>(new RawFloatSerialiser(), new RBMBackedTimestampSetSerialiser()); expectedMap.put(123.3f, timestampSet1); expectedMap.put(345.6f, timestampSet2); final String expectedJson = jsonFromFile("custom-map04.json"); final byte[] serialise = JSONSerialiser.serialise(expectedMap, true); final CustomMap jsonMap = JSONSerialiser.deserialise(expectedJson, CustomMap.class); final CustomMap deserialiseMap = JSONSerialiser.deserialise(serialise, CustomMap.class); assertEquals(jsonMap, deserialiseMap, "The expected map from Json doesn't match"); assertEquals(expectedMap, deserialiseMap, "The expected map doesn't match"); }