JsonObjectMapper { public <T> T deserializeBackwardsCompatibleValue(final String stringValue, final Class<T> type) throws IOException { try { return snakeCaseMapper.readValue(stringValue, type); } catch (final Exception e) { final ObjectMapper camelCaseMapper = new ObjectMapper() .registerModule(TimeModuleFactory.Companion.createTimeModule()) .setPropertyNamingStrategy(LOWER_CAMEL_CASE); return camelCaseMapper.readValue(stringValue, type); } } JsonObjectMapper(); String writeValueAsString(final Object object); T deserializeBackwardsCompatibleValue(final String stringValue, final Class<T> type); T readValue(final String stringValue, final Class<T> type); JsonNode readTree(final String stringValue);  }
@Test public void deserializeBackwardsCompatibleValue_supportsSnakeCaseDeserialization() throws IOException { final String testSnakeCaseString = "{\"exclude_lower\":true,\"include_special\":true}"; final StringGenerationParameters generationParameters = new StringGenerationParameters(); generationParameters.setExcludeLower(true); generationParameters.setIncludeSpecial(true); final StringGenerationParameters actualGenerationParameters = new JsonObjectMapper() .deserializeBackwardsCompatibleValue(testSnakeCaseString, StringGenerationParameters.class); assertThat(generationParameters, equalTo(actualGenerationParameters)); }
@Test public void deserializeBackwardsCompatibleValue_supportsCamelCaseDeserialization() throws IOException { final String testSnakeCaseString = "{\"excludeLower\":true,\"includeSpecial\":true}"; final StringGenerationParameters generationParameters = new StringGenerationParameters(); generationParameters.setExcludeLower(true); generationParameters.setIncludeSpecial(true); final StringGenerationParameters actualGenerationParameters = new JsonObjectMapper() .deserializeBackwardsCompatibleValue(testSnakeCaseString, StringGenerationParameters.class); assertThat(generationParameters, equalTo(actualGenerationParameters)); }