本文整理了Java中com.fasterxml.jackson.databind.ObjectMapper.setLocale()
方法的一些代码示例,展示了ObjectMapper.setLocale()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ObjectMapper.setLocale()
方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.ObjectMapper
类名称:ObjectMapper
方法名:setLocale
[英]Method for overriding default locale to use for formatting. Default value used is Locale#getDefault().
[中]方法重写用于格式化的默认区域设置。使用的默认值是Locale#getDefault()。
代码示例来源:origin: jooby-project/jooby
m.setLocale(locale);
m.setTimeZone(TimeZone.getTimeZone(config.getString("application.tz")));
代码示例来源:origin: spring-projects/spring-framework
objectMapper.setLocale(this.locale);
代码示例来源:origin: org.springframework/spring-web
objectMapper.setLocale(this.locale);
代码示例来源:origin: geosdi/geo-platform
/**
* @param locale
* @return {@link GPJacksonSupport}
*/
@Override
public GPJacksonSupport setLocale(Locale locale) {
this.mapper.setLocale(locale);
return this;
}
代码示例来源:origin: zhengjunbase/codehelper.generator
private static ObjectMapper getMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.setLocale(new Locale("zh", "CN"));
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
代码示例来源:origin: org.jooby/jooby-jackson
m.setLocale(locale);
m.setTimeZone(TimeZone.getTimeZone(config.getString("application.tz")));
代码示例来源:origin: chillzhuang/blade-tool
@Primary
@Bean
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
builder.simpleDateFormat(DateUtil.PATTERN_DATETIME);
//创建ObjectMapper
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
//设置地点为中国
objectMapper.setLocale(Locale.CHINA);
//去掉默认的时间戳格式
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
//设置为中国上海时区
objectMapper.setTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault()));
//序列化时,日期的统一格式
objectMapper.setDateFormat(new SimpleDateFormat(DateUtil.PATTERN_DATETIME, Locale.CHINA));
//序列化处理
objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
objectMapper.configure(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER, true);
objectMapper.findAndRegisterModules();
//失败处理
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//单引号处理
objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
//反序列化时,属性不存在的兼容处理
objectMapper.getDeserializationConfig().withoutFeatures(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
//日期格式化
objectMapper.registerModule(new BladeJavaTimeModule());
objectMapper.findAndRegisterModules();
return objectMapper;
}
代码示例来源:origin: io.micronaut/runtime
objectMapper.setLocale(locale);
代码示例来源:origin: chillzhuang/blade-tool
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(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
super.configure(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER, 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.setSerializerFactory(this.getSerializerFactory().withSerializerModifier(new BladeBeanSerializerModifier()));
super.getSerializerProvider().setNullValueSerializer(BladeBeanSerializerModifier.NullJsonSerializers.STRING_JSON_SERIALIZER);
//日期格式化
super.registerModule(new BladeJavaTimeModule());
super.findAndRegisterModules();
}
代码示例来源:origin: com.arakelian/jackson-utils
@Override
public JacksonProcessors load(final JacksonOptions opts) {
// same configuration as default mapper, but with different locale
final ObjectMapper mapper = opts.defaultMapper != null ? opts.defaultMapper.copy()
: new ObjectMapper();
mapper.setLocale(opts.getLocale());
// add request-specific modules
for (final Module module : opts.getModules()) {
mapper.registerModule(module);
}
for (final MapperFeature feature : opts.getEnabled()) {
mapper.enable(feature);
}
for (final MapperFeature feature : opts.getDisabled()) {
mapper.disable(feature);
}
final Class> view = opts.getView();
final boolean pretty = opts.isPretty();
final ObjectWriter writer;
if (view != null) {
// view-based rendering
writer = pretty ? mapper.writerWithView(view).withDefaultPrettyPrinter()
: mapper.writerWithView(view);
} else {
writer = pretty ? mapper.writerWithDefaultPrettyPrinter() : mapper.writer();
}
return new JacksonProcessors(mapper, writer);
}
});
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-web
objectMapper.setLocale(this.locale);
代码示例来源:origin: apache/servicemix-bundles
objectMapper.setLocale(this.locale);
代码示例来源:origin: com.bbossgroups/bboss-mvc
objectMapper.setLocale(this.locale);
代码示例来源:origin: com.googlecode.wicked-charts/wicked-charts-highcharts
@SuppressWarnings({ "rawtypes", "unchecked" })
private ObjectMapper createJacksonMapper() {
this.jacksonModule.addSerializer(Center.class, new CenterSerializer());
this.jacksonModule.addSerializer(SimpleColor.class, new SimpleColorReferenceSerializer());
this.jacksonModule.addSerializer(HighchartsColor.class, new HighchartsColorReferenceSerializer());
this.jacksonModule.addSerializer(HexColor.class, new HexColorReferenceSerializer());
this.jacksonModule.addSerializer(LowercaseEnum.class, new LowercaseEnumSerializer());
this.jacksonModule.addSerializer(PixelOrPercent.class, new PixelOrPercentSerializer());
this.jacksonModule.addSerializer(Symbol.class, new SymbolSerializer());
this.jacksonModule.addSerializer(RgbaColor.class, new RgbaColorReferenceSerializer());
this.jacksonModule.addSerializer(NullColor.class, new NullColorReferenceSerializer());
this.jacksonModule.addSerializer(MinorTickInterval.class, new MinorTickIntervalSerializer());
this.jacksonModule.addSerializer(Function.class, new FunctionSerializer());
this.jacksonModule.addSerializer(CssStyle.class, new CssStyleSerializer());
this.jacksonModule.addSerializer(DateTimeLabelFormat.class, new DateTimeLabelFormatSerializer());
this.jacksonModule.addSerializer(Coordinate.class, new CoordinateSerializer());
this.jacksonModule.addSerializer(Crosshair.class, new CrosshairSerializer());
this.jacksonModule.addSerializer(RangeCoordinate.class, new RangeCoordinateSerializer());
this.jacksonModule.addSerializer(Bubble.class, new BubbleSerializer());
ObjectMapper mapper = createDefaultObjectMapper();
mapper.setLocale(Locale.ENGLISH);
mapper.registerModule(this.jacksonModule);
return mapper;
}