com.fasterxml.jackson.databind.PropertyNamingStrategy Java Examples

The following examples show how to use com.fasterxml.jackson.databind.PropertyNamingStrategy. 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: JacksonJson.java    From choerodon-starters with Apache License 2.0 6 votes vote down vote up
public JacksonJson() {

        objectMapper = new ObjectMapper();

        objectMapper.setSerializationInclusion(Include.NON_NULL);
        objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);

        objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
        objectMapper.configure(SerializationFeature.WRITE_ENUMS_USING_TO_STRING, true);
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        objectMapper.configure(DeserializationFeature.READ_ENUMS_USING_TO_STRING, true);

        SimpleModule module = new SimpleModule("GitLabApiJsonModule");
        module.addSerializer(Date.class, new JsonDateSerializer());
        module.addDeserializer(Date.class, new JsonDateDeserializer());
        objectMapper.registerModule(module);
    }
 
Example #2
Source File: Range56Test.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
public void testSnakeCaseNamingStrategy() throws Exception
{
    String json = "{\"lower_endpoint\": 12, \"lower_bound_type\": \"CLOSED\", \"upper_endpoint\": 33, \"upper_bound_type\": \"CLOSED\"}";

    GuavaModule mod = new GuavaModule().defaultBoundType(BoundType.CLOSED);
    ObjectMapper mapper = JsonMapper.builder()
            .addModule(mod)
            .propertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
            .build();

    @SuppressWarnings("unchecked")
    Range<Integer> r = (Range<Integer>) mapper.readValue(json, Range.class);

    assertEquals(Integer.valueOf(12), r.lowerEndpoint());
    assertEquals(Integer.valueOf(33), r.upperEndpoint());

    assertEquals(BoundType.CLOSED, r.lowerBoundType());
    assertEquals(BoundType.CLOSED, r.upperBoundType());
}
 
Example #3
Source File: TestRange.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
public void testSnakeCaseNamingStrategy() throws Exception
{
    String json = "{\"lower_endpoint\": 12, \"lower_bound_type\": \"CLOSED\", \"upper_endpoint\": 33, \"upper_bound_type\": \"CLOSED\"}";

    GuavaModule mod = new GuavaModule().defaultBoundType(BoundType.CLOSED);
    ObjectMapper mapper = JsonMapper.builder()
            .addModule(mod)
            .propertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
            .build();

    @SuppressWarnings("unchecked")
    Range<Integer> r = (Range<Integer>) mapper.readValue(json, Range.class);

    assertEquals(Integer.valueOf(12), r.lowerEndpoint());
    assertEquals(Integer.valueOf(33), r.upperEndpoint());

    assertEquals(BoundType.CLOSED, r.lowerBoundType());
    assertEquals(BoundType.CLOSED, r.upperBoundType());
}
 
Example #4
Source File: ValidatedConfiguration.java    From divolte-collector with Apache License 2.0 6 votes vote down vote up
private static DivolteConfiguration mapped(final Config input) throws IOException {
    final Config resolved = input.resolve();
    final ObjectMapper mapper = new ObjectMapper();

    // snake_casing
    mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);

    // Ignore unknown stuff in the config
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);

    // Deserialization for Duration
    final SimpleModule module = new SimpleModule("Configuration Deserializers");
    module.addDeserializer(Duration.class, new DurationDeserializer());
    module.addDeserializer(Properties.class, new PropertiesDeserializer());

    mapper.registerModules(
            new Jdk8Module(),                   // JDK8 types (Optional, etc.)
            new GuavaModule(),                  // Guava types (immutable collections)
            new ParameterNamesModule(),         // Support JDK8 parameter name discovery
            module                              // Register custom deserializers module
            );

    return mapper.readValue(new HoconTreeTraversingParser(resolved.root()), DivolteConfiguration.class);
}
 
Example #5
Source File: BenderConfig.java    From bender with Apache License 2.0 6 votes vote down vote up
public static BenderConfig load(String filename, String data) {
  /*
   * Configure Mapper and register polymorphic types
   */
  ObjectMapper mapper = BenderConfig.getObjectMapper(filename);
  mapper.setPropertyNamingStrategy(
      PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);

  /*
   * Optionally don't validate the config. Assume user has already
   * done this.
   */
  String v = System.getenv("BENDER_SKIP_VALIDATE");
  if (v != null && v.equals("true")) {
    return BenderConfig.load(filename, data, mapper, false);
  } else {
    return BenderConfig.load(filename, data, mapper, true);
  }
}
 
Example #6
Source File: ModelObjectMapperTest.java    From line-bot-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void createdInstanceIsIsolatedTest() {
    final ObjectMapper first = ModelObjectMapper.createNewObjectMapper();
    final ObjectMapper second = ModelObjectMapper.createNewObjectMapper();

    // Precondition
    assertThat(first).isNotEqualTo(second);
    assertThat(first.getPropertyNamingStrategy())
            .isEqualTo(second.getPropertyNamingStrategy())
            .isNull();

    // Do
    first.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);

    // Verify
    assertThat(first.getPropertyNamingStrategy())
            .isNotEqualTo(second.getPropertyNamingStrategy());
}
 
Example #7
Source File: JacksonFactory.java    From pardot-java-client with MIT License 6 votes vote down vote up
/**
 * Creates properly configured Jackson XML Mapper instances.
 * @return XmlMapper instance.
 */
public static XmlMapper newInstance() {
    if (instance != null) {
        return instance;
    }

    // Create new mapper
    final JacksonXmlModule module = new JacksonXmlModule();
    module.setDefaultUseWrapper(false);
    module.addDeserializer(ProspectCustomFieldValue.class, new ProspectCustomFieldDeserializer());

    final XmlMapper mapper = new XmlMapper(module);

    // Configure it
    mapper
        .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
        .setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
        .registerModule(new JodaModule())
        .setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));

    return mapper;
}
 
Example #8
Source File: GcloudExecutor.java    From spydra with Apache License 2.0 6 votes vote down vote up
public Optional<Cluster> createCluster(String name, String region, Map<String, String> args)
    throws IOException {
  Map<String, String> createOptions = new HashMap<>(args);
  createOptions.put(SpydraArgument.OPTION_REGION, region);
  List<String> command = Arrays.asList(
      "--format=json", "beta", "dataproc", "clusters", "create", name);
  StringBuilder outputBuilder = new StringBuilder();
  boolean success = ProcessHelper.executeForOutput(
      buildCommand(command, createOptions, Collections.emptyList()),
      outputBuilder);
  String output = outputBuilder.toString();
  if (success) {
    Cluster cluster = JsonHelper.objectMapper()
        .setPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CAMEL_CASE)
        .readValue(output, Cluster.class);
    return Optional.of(cluster);
  } else {
    if (output.contains("ALREADY_EXISTS")) {
      throw new GcloudClusterAlreadyExistsException(output);
    }
    LOGGER.error("Dataproc cluster creation call failed. Command line output:");
    LOGGER.error(output);
    return Optional.empty();
  }
}
 
Example #9
Source File: ManagementConfiguration.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 6 votes vote down vote up
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.
            json().
            //propertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE).
            propertyNamingStrategy(PropertyNamingStrategy.LOWER_CAMEL_CASE).
            //featuresToEnable(SerializationFeature.INDENT_OUTPUT).
            //featuresToEnable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY).
            build();
    SimpleModule module = new SimpleModule();
    module.addSerializer(Set.class,
            new StdDelegatingSerializer(Set.class, new StdConverter<Set, List>() {
                @Override
                public List convert(Set value) {
                    LinkedList list = new LinkedList(value);
                    Collections.sort(list);
                    return list;
                }
            })
    );
    objectMapper.registerModule(module);
    HttpMessageConverter c = new MappingJackson2HttpMessageConverter(
            objectMapper
    );
    converters.add(c);
}
 
Example #10
Source File: ManagementConfiguration.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 6 votes vote down vote up
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.
            json().
            //propertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE).
            propertyNamingStrategy(PropertyNamingStrategy.LOWER_CAMEL_CASE).
            //featuresToEnable(SerializationFeature.INDENT_OUTPUT).
            //featuresToEnable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY).
            build();
    SimpleModule module = new SimpleModule();
    module.addSerializer(Set.class,
            new StdDelegatingSerializer(Set.class, new StdConverter<Set, List>() {
                @Override
                public List convert(Set value) {
                    LinkedList list = new LinkedList(value);
                    Collections.sort(list);
                    return list;
                }
            })
    );
    objectMapper.registerModule(module);
    HttpMessageConverter c = new MappingJackson2HttpMessageConverter(
            objectMapper
    );
    converters.add(c);
}
 
Example #11
Source File: QuarkusJsonPlatformDescriptorLoaderImpl.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public QuarkusJsonPlatformDescriptor load(final QuarkusJsonPlatformDescriptorLoaderContext context) {

    final QuarkusJsonPlatformDescriptor platform = context
            .parseJson(is -> {
                try {
                    ObjectMapper mapper = new ObjectMapper()
                            .enable(JsonParser.Feature.ALLOW_COMMENTS)
                            .enable(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS)
                            .setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE);
                    return mapper.readValue(is, QuarkusJsonPlatformDescriptor.class);
                } catch (IOException e) {
                    throw new RuntimeException("Failed to parse JSON stream", e);
                }
            });

    if (context.getArtifactResolver() != null) {
        platform.setManagedDependencies(context.getArtifactResolver().getManagedDependencies(platform.getBomGroupId(),
                platform.getBomArtifactId(), null, "pom", platform.getBomVersion()));
    }
    platform.setResourceLoader(context.getResourceLoader());
    platform.setMessageWriter(context.getMessageWriter());

    return platform;
}
 
Example #12
Source File: PatreonAPI.java    From patreon-java with Apache License 2.0 6 votes vote down vote up
/**
 * For use in test.
 */
PatreonAPI(String accessToken, RequestUtil requestUtil) {
  this.accessToken = accessToken;
  this.requestUtil = requestUtil;

  ObjectMapper objectMapper = new ObjectMapper();
  objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
  objectMapper.configure(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  this.converter = new ResourceConverter(
    objectMapper,
    User.class,
    Campaign.class,
    Pledge.class
  );
  this.converter.enableDeserializationOption(DeserializationFeature.ALLOW_UNKNOWN_INCLUSIONS);
}
 
Example #13
Source File: PropertyNamingStrategyWrapper.java    From jackson-datatype-protobuf with Apache License 2.0 5 votes vote down vote up
public PropertyNamingStrategyWrapper(PropertyNamingStrategy delegate) {
  if (delegate instanceof PropertyNamingStrategyBase) {
    this.delegate = (PropertyNamingStrategyBase) delegate;
  } else if (delegate == PropertyNamingStrategy.LOWER_CAMEL_CASE) {
    this.delegate = NO_OP;
  } else {
    this.delegate = SNAKE_TO_CAMEL;
  }
}
 
Example #14
Source File: JsonApiHttpMessageConverter.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
public JsonApiHttpMessageConverter(Class<?>... classes) {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
    objectMapper.configure(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    this.converter = new ResourceConverter(classes);
    this.converter.enableDeserializationOption(DeserializationFeature.ALLOW_UNKNOWN_INCLUSIONS);
}
 
Example #15
Source File: Jackson2ObjectMapperBuilderTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void propertyNamingStrategy() {
	PropertyNamingStrategy strategy = new PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy();
	ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().propertyNamingStrategy(strategy).build();
	assertSame(strategy, objectMapper.getSerializationConfig().getPropertyNamingStrategy());
	assertSame(strategy, objectMapper.getDeserializationConfig().getPropertyNamingStrategy());
}
 
Example #16
Source File: JacksonWrapper.java    From jlineup with Apache License 2.0 5 votes vote down vote up
public static String serializeObjectWithPropertyNamingStrategy(Object object, PropertyNamingStrategy propertyNamingStrategy) {
    try {
        return objectMapper().copy().setPropertyNamingStrategy(propertyNamingStrategy).writeValueAsString(object);
    } catch (JsonProcessingException e) {
        throw new RuntimeException("There is a problem while writing the " + object.getClass().getCanonicalName() + " with Jackson.", e);
    }
}
 
Example #17
Source File: Jackson2ObjectMapperFactoryBeanTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void propertyNamingStrategy() {
	PropertyNamingStrategy strategy = new PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy();
	this.factory.setPropertyNamingStrategy(strategy);
	this.factory.afterPropertiesSet();

	assertSame(strategy, this.factory.getObject().getSerializationConfig().getPropertyNamingStrategy());
	assertSame(strategy, this.factory.getObject().getDeserializationConfig().getPropertyNamingStrategy());
}
 
Example #18
Source File: RangeHelper.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
public static RangeProperties getPropertyNames(MapperConfig<?> config, PropertyNamingStrategy pns) {
    return new RangeProperties(
            _find(config, pns, "lowerEndpoint"),
            _find(config, pns, "upperEndpoint"),
            _find(config, pns, "lowerBoundType"),
            _find(config, pns, "upperBoundType")
    );
}
 
Example #19
Source File: BugsTest.java    From immutables with Apache License 2.0 5 votes vote down vote up
@Test
public void roundtrip353() throws Exception {
  ObjectMapper mapper = new ObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
  String json = mapper.writeValueAsString(ImmutableNamingStrategy.builder()
      .abraCadabra(1)
      .focusPocus(true)
      .build());

  NamingStrategy info = mapper.readValue(json, NamingStrategy.class);
  check(info.abraCadabra()).is(1);
  check(info.focusPocus());

  check(json).is("{'abra_cadabra':1,'focus_pocus':true}".replace('\'', '"'));
}
 
Example #20
Source File: PropertyNamingTest.java    From jackson-datatype-protobuf with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultipleStillCamelCase() {
  List<PropertyNamingCamelCased> messages = ProtobufCreator.create(PropertyNamingCamelCased.class, 10);

  @SuppressWarnings("serial")
  ObjectMapper mapper = new ObjectMapper().registerModule(new ProtobufModule()).setPropertyNamingStrategy(
      new PropertyNamingStrategy.PropertyNamingStrategyBase() {
        @Override
        public String translate(String propertyName) {
          return propertyName;
        }
      });

  JsonNode tree = toTree(mapper, messages);

  assertThat(tree).isInstanceOf(ArrayNode.class);
  assertThat(tree.size()).isEqualTo(10);

  for (int i = 0; i < 10; i++) {
    JsonNode subTree = tree.get(i);

    assertThat(subTree.isObject()).isTrue();
    assertThat(subTree.size()).isEqualTo(1);
    assertThat(subTree.get("stringAttribute")).isNotNull();
    assertThat(subTree.get("stringAttribute").textValue()).isEqualTo(messages.get(i).getStringAttribute());
  }
}
 
Example #21
Source File: TestCaseValidationSpringConfig.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    converters.clear();
    converters.add(new ByteArrayHttpMessageConverter());
    converters.add(new StringHttpMessageConverter());
    final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    final ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
    converter.setObjectMapper(objectMapper);
    converters.add(converter);
    super.configureMessageConverters(converters);
}
 
Example #22
Source File: ResourceFieldNameTransformerTest.java    From katharsis-framework with Apache License 2.0 5 votes vote down vote up
@Test
public void onMethodNameWithNamingStrategyShouldReturnModifiedName() throws Exception {
    // GIVEN
    objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
    sut = new ResourceFieldNameTransformer(objectMapper.getSerializationConfig());
    Method method = TestClass.class.getDeclaredMethod("getAccessorField");

    // WHEN
    String name = sut.getName(method);

    // THEN
    assertThat(name).isEqualTo("accessor_field");
}
 
Example #23
Source File: HuobiApiClient.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
static ObjectMapper createObjectMapper() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE);
    mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
    // disabled features:
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    return mapper;
}
 
Example #24
Source File: ResourceFieldNameTransformerTest.java    From katharsis-framework with Apache License 2.0 5 votes vote down vote up
@Test
public void onFieldNameWithNamingStrategyShouldReturnModifiedName() throws Exception {
    // GIVEN
    objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
    sut = new ResourceFieldNameTransformer(objectMapper.getSerializationConfig());
    Field field = TestClass.class.getDeclaredField("namingStrategyTest");

    // WHEN
    String name = sut.getName(field);

    // THEN
    assertThat(name).isEqualTo("naming_strategy_test");
}
 
Example #25
Source File: AwsStsHttpClient.java    From cerberus with Apache License 2.0 5 votes vote down vote up
public AwsStsHttpClient() {
  objectMapper = new ObjectMapper();
  objectMapper.findAndRegisterModules();
  objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE);
  objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

  httpClient =
      new OkHttpClient.Builder()
          .connectTimeout(DEFAULT_TIMEOUT, DEFAULT_TIMEOUT_UNIT)
          .writeTimeout(DEFAULT_TIMEOUT, DEFAULT_TIMEOUT_UNIT)
          .readTimeout(DEFAULT_TIMEOUT, DEFAULT_TIMEOUT_UNIT)
          .build();
}
 
Example #26
Source File: GenerateExtensionsJsonMojo.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private ObjectMapper getMapper(boolean yaml) {

        if (yaml) {
            YAMLFactory yf = new YAMLFactory();
            return new ObjectMapper(yf)
                    .setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE);
        } else {
            return new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT)
                    .enable(JsonParser.Feature.ALLOW_COMMENTS).enable(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS)
                    .setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE);
        }
    }
 
Example #27
Source File: ExtensionDescriptorMojo.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private ObjectMapper getMapper(boolean yaml) {

        if (yaml) {
            YAMLFactory yf = new YAMLFactory();
            return new ObjectMapper(yf)
                    .setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE);
        } else {
            return new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT)
                    .enable(JsonParser.Feature.ALLOW_COMMENTS).enable(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS)
                    .setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE);
        }
    }
 
Example #28
Source File: JsonUtils.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a default json mapper.
 *
 * @param strategy property naming strategy
 * @return object mapper
 */
@NonNull
public static ObjectMapper createDefaultJsonMapper(@Nullable PropertyNamingStrategy strategy) {
    // Create object mapper
    ObjectMapper mapper = new ObjectMapper();
    // Configure
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    // Set property naming strategy
    if (strategy != null) {
        mapper.setPropertyNamingStrategy(strategy);
    }
    return mapper;
}
 
Example #29
Source File: AutoMatterModuleTest.java    From auto-matter with Apache License 2.0 5 votes vote down vote up
@Test
public void testSnakeCaseNamingStrategy() throws IOException {
  Assume.assumeTrue(mapper.version().getMajorVersion() == 2 && mapper.version().getMinorVersion() >= 7);
  mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
  final String json = mapper.writeValueAsString(FOO);
  final JsonNode tree = mapper.readTree(json);
  assertThat(tree.has("a_camel_case_field"), is(true));
  final Foo parsed = mapper.readValue(json, Foo.class);
  assertThat(parsed, is(FOO));
}
 
Example #30
Source File: ApplicationConfiguration.java    From cerberus with Apache License 2.0 5 votes vote down vote up
public static ObjectMapper getObjectMapper() {
  ObjectMapper om = new ObjectMapper();
  om.findAndRegisterModules();
  om.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
  om.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
  om.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
  om.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
  om.enable(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS);
  om.enable(SerializationFeature.INDENT_OUTPUT);
  return om;
}