本文整理了Java中com.fasterxml.jackson.databind.ObjectMapper.disable()
方法的一些代码示例,展示了ObjectMapper.disable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ObjectMapper.disable()
方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.ObjectMapper
类名称:ObjectMapper
方法名:disable
[英]Method for enabling specified DeserializationConfig features. Modifies and returns this instance; no new object is created.
[中]用于启用指定的反序列化配置功能的方法。修改并返回此实例;不创建新对象。
代码示例来源:origin: springside/springside4
public JsonMapper(Include include) {
mapper = new ObjectMapper();
// 设置输出时包含属性的风格
if (include != null) {
mapper.setSerializationInclusion(include);
}
// 设置输入时忽略在JSON字符串中存在但Java对象实际没有的属性
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
}
代码示例来源:origin: vipshop/vjtools
public JsonMapper(Include include) {
mapper = new ObjectMapper();
// 设置输出时包含属性的风格
if (include != null) {
mapper.setSerializationInclusion(include);
}
// 设置输入时忽略在JSON字符串中存在但Java对象实际没有的属性
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
}
代码示例来源:origin: auth0/java-jwt
static ObjectMapper getDefaultObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
return mapper;
}
代码示例来源:origin: stackoverflow.com
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
代码示例来源:origin: confluentinc/ksql
public Console(
final OutputFormat outputFormat,
final KsqlTerminal terminal,
final RowCaptor rowCaptor
) {
this.outputFormat = Objects.requireNonNull(outputFormat, "outputFormat");
this.terminal = Objects.requireNonNull(terminal, "terminal");
this.rowCaptor = Objects.requireNonNull(rowCaptor, "rowCaptor");
this.cliSpecificCommands = Maps.newLinkedHashMap();
this.objectMapper = new ObjectMapper().disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
}
代码示例来源:origin: allure-framework/allure2
public JacksonContext() {
this.mapper = new ObjectMapper()
.enable(SerializationFeature.INDENT_OUTPUT)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
代码示例来源:origin: twitter/ambrose
private static ObjectMapper newMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT, false);
mapper.disable(SerializationFeature.FLUSH_AFTER_WRITE_VALUE);
mapper.disable(SerializationFeature.CLOSE_CLOSEABLE);
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
Reflections reflections = new Reflections("com.twitter.ambrose");
Set<Class<? extends Job>> jobSubTypes = reflections.getSubTypesOf(Job.class);
mapper.registerSubtypes(jobSubTypes.toArray(new Class<?>[jobSubTypes.size()]));
return mapper;
}
}
代码示例来源:origin: killbill/killbill
@Inject
public NodeInfoMapper() {
this.mapper = new ObjectMapper();
mapper.registerModule(new JodaModule());
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
}
代码示例来源:origin: ethereum/ethereumj
public static GenesisJson loadGenesisJson(InputStream genesisJsonIS) throws RuntimeException {
String json = null;
try {
json = new String(ByteStreams.toByteArray(genesisJsonIS));
ObjectMapper mapper = new ObjectMapper()
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
GenesisJson genesisJson = mapper.readValue(json, GenesisJson.class);
return genesisJson;
} catch (Exception e) {
Utils.showErrorAndExit("Problem parsing genesis: "+ e.getMessage(), json);
throw new RuntimeException(e.getMessage(), e);
}
}
代码示例来源:origin: dropwizard/dropwizard
/**
* Creates a new minimal {@link ObjectMapper} that will work with Dropwizard out of box.
* <p><b>NOTE:</b> Use it, if the default Dropwizard's {@link ObjectMapper}, created in
* {@link #newObjectMapper()}, is too aggressive for you.</p>
*/
public static ObjectMapper newMinimalObjectMapper() {
return new ObjectMapper()
.registerModule(new GuavaModule())
.setSubtypeResolver(new DiscoverableSubtypeResolver())
.disable(FAIL_ON_UNKNOWN_PROPERTIES);
}
代码示例来源:origin: apache/kylin
public TimedJsonStreamParser(List<TblColRef> allColumns, Map<String, String> properties) {
this.allColumns = allColumns;
if (properties == null) {
properties = StreamingParser.defaultProperties;
}
tsColName = properties.get(PROPERTY_TS_COLUMN_NAME);
tsParser = properties.get(PROPERTY_TS_PARSER);
separator = properties.get(PROPERTY_EMBEDDED_SEPARATOR);
strictCheck = Boolean.parseBoolean(properties.get(PROPERTY_STRICT_CHECK));
if (!StringUtils.isEmpty(tsParser)) {
try {
Class clazz = Class.forName(tsParser);
Constructor constructor = clazz.getConstructor(Map.class);
streamTimeParser = (AbstractTimeParser) constructor.newInstance(properties);
} catch (Exception e) {
throw new IllegalStateException("Invalid StreamingConfig, tsParser " + tsParser + ", parserProperties " + properties + ".", e);
}
} else {
throw new IllegalStateException("Invalid StreamingConfig, tsParser " + tsParser + ", parserProperties " + properties + ".");
}
mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.disable(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE);
mapper.enable(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY);
}
代码示例来源:origin: twosigma/beakerx
@BeforeClass
public static void setUpClass() throws Exception {
mapper = new ObjectMapper();
mapper.disable(MapperFeature.AUTO_DETECT_GETTERS);
mapper.disable(MapperFeature.AUTO_DETECT_IS_GETTERS);
mapper.disable(MapperFeature.AUTO_DETECT_FIELDS);
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
jgen = mapper.getFactory().createGenerator(new StringWriter());
}
代码示例来源:origin: twosigma/beakerx
@BeforeClass
public static void initClassStubData() {
mapper = new ObjectMapper();
mapper.disable(MapperFeature.AUTO_DETECT_GETTERS);
mapper.disable(MapperFeature.AUTO_DETECT_IS_GETTERS);
mapper.disable(MapperFeature.AUTO_DETECT_FIELDS);
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
treeMapSerializer = new TreeMapSerializer();
}
代码示例来源:origin: twosigma/beakerx
@BeforeClass
public static void initClassStubData() {
mapper = new ObjectMapper();
mapper.disable(MapperFeature.AUTO_DETECT_GETTERS);
mapper.disable(MapperFeature.AUTO_DETECT_IS_GETTERS);
mapper.disable(MapperFeature.AUTO_DETECT_FIELDS);
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
treeMapNodeSerializer = new TreeMapNodeSerializer();
}
代码示例来源:origin: redisson/redisson
protected void init(ObjectMapper objectMapper) {
objectMapper.setSerializationInclusion(Include.NON_NULL);
objectMapper.setVisibility(objectMapper.getSerializationConfig()
.getDefaultVisibilityChecker()
.withFieldVisibility(JsonAutoDetect.Visibility.ANY)
.withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withSetterVisibility(JsonAutoDetect.Visibility.NONE)
.withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
objectMapper.enable(Feature.WRITE_BIGDECIMAL_AS_PLAIN);
objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
objectMapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
objectMapper.addMixIn(Throwable.class, ThrowableMixIn.class);
}
代码示例来源:origin: redisson/redisson
protected void init(ObjectMapper objectMapper) {
objectMapper.setSerializationInclusion(Include.NON_NULL);
objectMapper.setVisibility(objectMapper.getSerializationConfig()
.getDefaultVisibilityChecker()
.withFieldVisibility(JsonAutoDetect.Visibility.ANY)
.withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withSetterVisibility(JsonAutoDetect.Visibility.NONE)
.withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
objectMapper.enable(Feature.WRITE_BIGDECIMAL_AS_PLAIN);
objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
objectMapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
objectMapper.addMixIn(Throwable.class, ThrowableMixIn.class);
}
代码示例来源:origin: dropwizard/dropwizard
private static ObjectMapper configure(ObjectMapper mapper) {
mapper.registerModule(new GuavaModule());
mapper.registerModule(new GuavaExtrasModule());
mapper.registerModule(new CaffeineModule());
mapper.registerModule(new JodaModule());
mapper.registerModule(new AfterburnerModule());
mapper.registerModule(new FuzzyEnumModule());
mapper.registerModule(new ParameterNamesModule());
mapper.registerModule(new Jdk8Module());
mapper.registerModule(new JavaTimeModule());
mapper.setPropertyNamingStrategy(new AnnotationSensitivePropertyNamingStrategy());
mapper.setSubtypeResolver(new DiscoverableSubtypeResolver());
mapper.disable(FAIL_ON_UNKNOWN_PROPERTIES);
return mapper;
}
}
代码示例来源:origin: gchq/Gaffer
public static ObjectMapper createDefaultMapper() {
final ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
mapper.configure(SerializationFeature.CLOSE_CLOSEABLE, true);
mapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
mapper.registerModule(CloseableIterableDeserializer.getModule());
// Allow unknown properties. This will help to avoid conflicts between Gaffer versions.
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, STRICT_JSON_DEFAULT);
// Using the deprecated version for compatibility with older versions of jackson
mapper.registerModule(new JSR310Module());
// Use the 'setFilters' method so it is compatible with older versions of jackson
mapper.setFilters(getFilterProvider());
// Allow simple class names or full class names to be used in JSON.
// We must set this to true to ensure serialisation into json uses the
// full class name. Otherwise, json deserialisation may fail on worker nodes in Accumulo/HBase.
SimpleClassNameCache.setUseFullNameForSerialisation(true);
SimpleClassNameIdResolver.configureObjectMapper(mapper);
return mapper;
}
代码示例来源:origin: thymeleaf/thymeleaf
JacksonStandardJavaScriptSerializer(final String jacksonPrefix) {
super();
this.mapper = new ObjectMapper();
this.mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
this.mapper.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
this.mapper.enable(JsonGenerator.Feature.ESCAPE_NON_ASCII);
this.mapper.getFactory().setCharacterEscapes(new JacksonThymeleafCharacterEscapes());
this.mapper.setDateFormat(new JacksonThymeleafISO8601DateFormat());
/*
* Now try to (conditionally) initialize support for Jackson serialization of JSR310 (java.time) objects,
* by making use of the 'jackson-datatype-jsr310' optional dependency.
*/
final Class<?> javaTimeModuleClass =
ClassLoaderUtils.findClass(jacksonPrefix + ".datatype.jsr310.JavaTimeModule");
if (javaTimeModuleClass != null) {
// JSR310 support for Jackson is present in classpath
try {
this.mapper.registerModule((Module)javaTimeModuleClass.newInstance());
this.mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
} catch (final InstantiationException e) {
throw new ConfigurationException("Exception while trying to initialize JSR310 support for Jackson", e);
} catch (final IllegalAccessException e) {
throw new ConfigurationException("Exception while trying to initialize JSR310 support for Jackson", e);
}
}
}
代码示例来源:origin: Graylog2/graylog2-server
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
.disable(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY)
.setPropertyNamingStrategy(new PropertyNamingStrategy.SnakeCaseStrategy())
.setSubtypeResolver(subtypeResolver)
内容来源于网络,如有侵权,请联系作者删除!