com.fasterxml.jackson.databind.ObjectMapper.configure()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(266)

本文整理了Java中com.fasterxml.jackson.databind.ObjectMapper.configure()方法的一些代码示例,展示了ObjectMapper.configure()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ObjectMapper.configure()方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.ObjectMapper
类名称:ObjectMapper
方法名:configure

ObjectMapper.configure介绍

[英]Method for changing state of an on/off JsonGenerator feature for generator instances this object mapper creates.

Note that this is equivalent to directly calling same method on #getFactory.

WARNING: since this method directly modifies state of underlying JsonFactory, it will change observed configuration by ObjectWriters as well -- to avoid this, use ObjectWriter#with(JsonGenerator.Feature) instead.
[中]方法,用于更改此对象映射器创建的生成器实例的打开/关闭JsonGenerator功能的状态。
请注意,这相当于在#getFactory上直接调用相同的方法。
警告:由于此方法直接修改底层JsonFactory的状态,因此它还将更改ObjectWriter观察到的配置——为了避免这种情况,请改用ObjectWriter#with(jsongGenerator.Feature)。

代码示例

代码示例来源:origin: spring-projects/spring-framework

public MappingJackson2MessageConverter() {
  this.objectMapper = new ObjectMapper();
  this.objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
  this.objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}

代码示例来源:origin: spring-projects/spring-framework

private ObjectMapper initObjectMapper() {
  ObjectMapper objectMapper = new ObjectMapper();
  objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
  objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  return objectMapper;
}

代码示例来源:origin: apache/pulsar

public static ObjectMapper create() {
  ObjectMapper mapper = new ObjectMapper();
  // forward compatibility for the properties may go away in the future
  mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
  mapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, false);
  mapper.setSerializationInclusion(Include.NON_NULL);
  return mapper;
}

代码示例来源:origin: apache/pulsar

public static ObjectMapper create() {
  ObjectMapper mapper = new ObjectMapper();
  // forward compatibility for the properties may go away in the future
  mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  mapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
  mapper.setSerializationInclusion(Include.NON_NULL);
  return mapper;
}

代码示例来源:origin: databricks/learning-spark

static ObjectMapper createMapper() {
 ObjectMapper mapper = new ObjectMapper();
 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 return mapper;
}

代码示例来源:origin: stackoverflow.com

@Configuration
public class JacksonConfiguration {

  @Bean
  public ObjectMapper objectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true);

    return mapper;
  }
}

代码示例来源:origin: apache/zookeeper

public JsonOutputter() {
  mapper = new ObjectMapper();
  mapper.configure(SerializationFeature.WRITE_ENUMS_USING_TO_STRING, true);
  mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
  mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
}

代码示例来源:origin: Netflix/conductor

private static ObjectMapper objectMapper() {
  final ObjectMapper om = new ObjectMapper();
  om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  om.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false);
  om.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
  om.setSerializationInclusion(Include.NON_NULL);
  om.setSerializationInclusion(Include.NON_EMPTY);
  return om;
}

代码示例来源:origin: signalapp/Signal-Server

public DirectoryManager(ReplicatedJedisPool redisPool) {
 this.redisPool    = redisPool;
 this.objectMapper = new ObjectMapper();
 this.objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}

代码示例来源:origin: apache/pulsar

public static ObjectMapper createYaml() {
  ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
  // forward compatibility for the properties may go away in the future
  mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  mapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
  mapper.setSerializationInclusion(Include.NON_NULL);
  return mapper;
}

代码示例来源:origin: apache/drill

private static synchronized ObjectMapper getMapper(){
  if(MAPPER == null){
   ObjectMapper mapper = new ObjectMapper();
   mapper.enable(SerializationFeature.INDENT_OUTPUT);
   mapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
   mapper.configure(Feature.ALLOW_COMMENTS, true);
   MAPPER = mapper;
  }
  return MAPPER;
 }
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

public BanoGeocoder() {
  mapper = new ObjectMapper();
  mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}

代码示例来源:origin: ltsopensource/light-task-scheduler

public JacksonJSONAdapter() {
  mapper = new ObjectMapper();
  // 忽略多余的字段
  mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  // 不输出为空的字段
  mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}

代码示例来源:origin: ltsopensource/light-task-scheduler

public JacksonJSONAdapter() {
  mapper = new ObjectMapper();
  // 忽略多余的字段
  mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  // 不输出为空的字段
  mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}

代码示例来源:origin: apache/hive

RuntimeStatsPersister() {
 om = new ObjectMapper();
 om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
 om.configure(SerializationFeature.INDENT_OUTPUT, true);
 om.configure(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS, true);
}

代码示例来源:origin: stackoverflow.com

String x = "{'candidateId':'k','candEducationId':1,'activitiesSocieties':'Activities for cand1'}";
ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
JsonNode df = mapper.readValue(x, JsonNode.class);
System.out.println(df.toString());
// output: {"candidateId":"k","candEducationId":1,"activitiesSocieties":"Activities for cand1"}

代码示例来源:origin: Netflix/conductor

@Override
  public ObjectMapper get() {
    final ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false);
    objectMapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    objectMapper.registerModule(new JsonProtoModule());
    return objectMapper;
  }
}

代码示例来源:origin: stackoverflow.com

public String serialize(Object obj, boolean pretty) {
  ObjectMapper mapper = new ObjectMapper();

  mapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);

  if (pretty) {
    return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj);
  }

  return mapper.writeValueAsString(obj);
}

代码示例来源:origin: apache/geode

private static ObjectMapper createObjectMapper() {
 ObjectMapper mapper = new ObjectMapper();
 mapper.setDateFormat(new SimpleDateFormat("MM/dd/yyyy"));
 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 mapper.configure(com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES,
   true);
 return mapper;
}

代码示例来源:origin: jenkinsci/gitlab-plugin

public ObjectMapper getContext(Class<?> type) {
    return new ObjectMapper()
        .setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES)
        .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
        .configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
  }
}

相关文章

微信公众号

最新文章

更多

ObjectMapper类方法