@Test public void testInvalidKeysForClass() throws IOException { ObjectMapper objectMapper = ObjectMapperFactory.customObjectMapper(); String stringField = " \t field 1 "; List<String> stringListField = List.of("item 1 ", " item 2"); Map<String, String> stringMapField = Map.of(" key 1\t", "value 1 ", " key 2", " value 2"); Map<String, Object> model = Map.of("stringField ", stringField, " stringListField", stringListField, "stringMapField", stringMapField); String serialized = objectMapper.writeValueAsString(model); TestModel deserialized = ObjectMapperFactory.customObjectMapper().readValue(serialized, TestModel.class); Assert.assertEquals("field 1", deserialized.stringField); Assert.assertEquals(List.of("item 1", "item 2"), deserialized.stringListField); Assert.assertEquals(ImmutableMap.of("key 1", "value 1", "key 2", "value 2"), deserialized.stringMapField); }
@Bean public static ObjectMapper customObjectMapper() { return Jackson2ObjectMapperBuilder.json() .modules(new InstantJsonModule(), new Jdk8Module(), new TrimKeysModule(), new TrimValuesModule()) .build(); }
ObjectMapperFactory { @Bean public static ObjectMapper customObjectMapper() { return Jackson2ObjectMapperBuilder.json() .modules(new InstantJsonModule(), new Jdk8Module(), new TrimKeysModule(), new TrimValuesModule()) .build(); } }
ObjectMapperFactory { @Bean public static ObjectMapper customObjectMapper() { return Jackson2ObjectMapperBuilder.json() .modules(new InstantJsonModule(), new Jdk8Module(), new TrimKeysModule(), new TrimValuesModule()) .build(); }  }
ObjectMapperFactory { @Bean public static ObjectMapper customObjectMapper() { return Jackson2ObjectMapperBuilder.json() .modules(new InstantJsonModule(), new Jdk8Module(), new TrimKeysModule(), new TrimValuesModule()) .build(); }  @Bean static ObjectMapper customObjectMapper(); }
ObjectMapperFactory { @Bean public static ObjectMapper customObjectMapper() { return Jackson2ObjectMapperBuilder.json() .modules(new InstantJsonModule(), new Jdk8Module(), new TrimKeysModule(), new TrimValuesModule()) .build(); }  @Bean static ObjectMapper customObjectMapper();  }