com.fasterxml.jackson.core.json.JsonWriteFeature Java Examples

The following examples show how to use com.fasterxml.jackson.core.json.JsonWriteFeature. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpspClientDefaults.java    From quilt with Apache License 2.0 6 votes vote down vote up
private static ObjectMapper defaultMapper() {
  final ObjectMapper objectMapper = JsonMapper.builder()
      .serializationInclusion(JsonInclude.Include.NON_EMPTY)
      .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
      .configure(JsonWriteFeature.WRITE_NUMBERS_AS_STRINGS, false)
      .build()
      .registerModule(new Jdk8Module())
      .registerModule(new InterledgerModule(Encoding.BASE64));
  objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
  objectMapper.configure(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN, true);
  return objectMapper;
}
 
Example #2
Source File: MonetaryAmountSerializerTest.java    From jackson-datatype-money with MIT License 5 votes vote down vote up
@ParameterizedTest
@MethodSource("amounts")
void shouldWriteNumbersAsStrings(final MonetaryAmount amount) throws JsonProcessingException {
    final ObjectMapper unit = build()
            .enable(JsonWriteFeature.WRITE_NUMBERS_AS_STRINGS)
            .build();

    final String expected = "{\"amount\":\"29.95\",\"currency\":\"EUR\"}";
    final String actual = unit.writeValueAsString(amount);

    assertThat(actual, is(expected));
}
 
Example #3
Source File: MonetaryAmountSerializerTest.java    From jackson-datatype-money with MIT License 5 votes vote down vote up
@ParameterizedTest
@MethodSource("hundreds")
void shouldWriteNumbersAsPlainStrings(final MonetaryAmount hundred) throws JsonProcessingException {
    final ObjectMapper unit = build()
            .enable(JsonWriteFeature.WRITE_NUMBERS_AS_STRINGS)
            .enable(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN)
            .build();

    final String expected = "{\"amount\":\"100.00\",\"currency\":\"EUR\"}";
    final String actual = unit.writeValueAsString(hundred);

    assertThat(actual, is(expected));
}