@Test public void testCustomComparatorPasses() throws JsonProcessingException { CustomComparators comparators = new DeterministicObjectMapper.CustomComparators(); comparators.addConverter(MyObject.class, Comparator.comparing(MyObject::getX)); ObjectMapper customizedComparatorsMapper = DeterministicObjectMapper.create(Json.serializer().mapper(), comparators); Set<MyObject> objects = Seq.of( new MyObject(2), new MyObject(4), new MyObject(3), new MyObject(1) ).toSet(); String actual = customizedComparatorsMapper.writer().writeValueAsString(objects); String expected = "[{\"x\":1},{\"x\":2},{\"x\":3},{\"x\":4}]"; assertEquals(expected, actual); }
public static ObjectMapper create(ObjectMapper original, CustomComparators customComparators) { ObjectMapper mapper = original.copy() .configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true) .configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); SerializerProvider serializers = mapper.getSerializerProviderInstance(); SimpleModule module = new SimpleModule(); module.addSerializer(Collection.class, new CustomDelegatingSerializerProvider(serializers, new CollectionToSortedListConverter(customComparators)) ); mapper.registerModule(module); return mapper; }
DeterministicObjectMapper { public static ObjectMapper create(ObjectMapper original, CustomComparators customComparators) { ObjectMapper mapper = original.copy() .configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true) .configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); SerializerProvider serializers = mapper.getSerializerProviderInstance(); SimpleModule module = new SimpleModule(); module.addSerializer(Collection.class, new CustomDelegatingSerializerProvider(serializers, new CollectionToSortedListConverter(customComparators)) ); mapper.registerModule(module); return mapper; } }
DeterministicObjectMapper { public static ObjectMapper create(ObjectMapper original, CustomComparators customComparators) { ObjectMapper mapper = original.copy() .configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true) .configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); SerializerProvider serializers = mapper.getSerializerProviderInstance(); SimpleModule module = new SimpleModule(); module.addSerializer(Collection.class, new CustomDelegatingSerializerProvider(serializers, new CollectionToSortedListConverter(customComparators)) ); mapper.registerModule(module); return mapper; } private  DeterministicObjectMapper(); }
DeterministicObjectMapper { public static ObjectMapper create(ObjectMapper original, CustomComparators customComparators) { ObjectMapper mapper = original.copy() .configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true) .configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); SerializerProvider serializers = mapper.getSerializerProviderInstance(); SimpleModule module = new SimpleModule(); module.addSerializer(Collection.class, new CustomDelegatingSerializerProvider(serializers, new CollectionToSortedListConverter(customComparators)) ); mapper.registerModule(module); return mapper; } private  DeterministicObjectMapper(); static ObjectMapper create(ObjectMapper original, CustomComparators customComparators); }
DeterministicObjectMapper { public static ObjectMapper create(ObjectMapper original, CustomComparators customComparators) { ObjectMapper mapper = original.copy() .configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true) .configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); SerializerProvider serializers = mapper.getSerializerProviderInstance(); SimpleModule module = new SimpleModule(); module.addSerializer(Collection.class, new CustomDelegatingSerializerProvider(serializers, new CollectionToSortedListConverter(customComparators)) ); mapper.registerModule(module); return mapper; } private  DeterministicObjectMapper(); static ObjectMapper create(ObjectMapper original, CustomComparators customComparators);  }