下面列出了怎么用com.fasterxml.jackson.core.json.JsonReadFeature的API类实例代码及写法,或者点击链接到github查看源代码。
public JacksonObjectMapper() {
super();
//设置地点为中国
super.setLocale(CHINA);
//去掉默认的时间戳格式
super.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
//设置为中国上海时区
super.setTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault()));
//序列化时,日期的统一格式
super.setDateFormat(new SimpleDateFormat(DateUtil.PATTERN_DATETIME, Locale.CHINA));
//序列化处理
super.configure(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature(), true);
super.configure(JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER.mappedFeature(), true);
super.findAndRegisterModules();
//失败处理
super.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
super.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//单引号处理
super.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
//反序列化时,属性不存在的兼容处理s
super.getDeserializationConfig().withoutFeatures(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
//日期格式化
super.registerModule(new BladeJavaTimeModule());
super.findAndRegisterModules();
}
private static JsonFactory jsonFactory() {
return JsonFactory.builder()
// 可解析反斜杠引用的所有字符
.configure(JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER, true)
// 允许JSON字符串包含非引号控制字符(值小于32的ASCII字符,包含制表符和换行符)
.configure(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS, true)
.build();
}
@BeforeClass
public static void setUp() {
// Initialize object mapper for testing. With this configuration we save a lot of quotes and escaping when creating JSON strings.
mapper = JsonMapper.builder()
.enable(JsonReadFeature.ALLOW_UNQUOTED_FIELD_NAMES)
.enable(JsonReadFeature.ALLOW_SINGLE_QUOTES)
.build();
// Initialize validator for testing including custom mappings.
validator = Validation.byDefaultProvider()
.configure()
.addMapping(AbstractRequestTest.class.getClassLoader().getResourceAsStream(VALIDATION_MAPPINGS))
.buildValidatorFactory()
.getValidator();
}