本文整理汇总了Java中org.springframework.http.converter.json.Jackson2ObjectMapperBuilder类的典型用法代码示例。如果您正苦于以下问题:Java Jackson2ObjectMapperBuilder类的具体用法?Java Jackson2ObjectMapperBuilder怎么用?Java Jackson2ObjectMapperBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Jackson2ObjectMapperBuilder类属于org.springframework.http.converter.json包,在下文中一共展示了Jackson2ObjectMapperBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: defaultObjectMapperBuilder
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; //导入依赖的package包/类
@Test
public void defaultObjectMapperBuilder() throws Exception {
this.context.register(JacksonAutoConfiguration.class);
this.context.refresh();
Jackson2ObjectMapperBuilder builder = this.context
.getBean(Jackson2ObjectMapperBuilder.class);
ObjectMapper mapper = builder.build();
assertThat(MapperFeature.DEFAULT_VIEW_INCLUSION.enabledByDefault()).isTrue();
assertThat(mapper.getDeserializationConfig()
.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION)).isFalse();
assertThat(MapperFeature.DEFAULT_VIEW_INCLUSION.enabledByDefault()).isTrue();
assertThat(mapper.getDeserializationConfig()
.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION)).isFalse();
assertThat(mapper.getSerializationConfig()
.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION)).isFalse();
assertThat(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES.enabledByDefault())
.isTrue();
assertThat(mapper.getDeserializationConfig()
.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)).isFalse();
}
示例2: configProtobufSerializer
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; //导入依赖的package包/类
@Bean
public Jackson2ObjectMapperBuilderCustomizer configProtobufSerializer() {
return new Jackson2ObjectMapperBuilderCustomizer() {
@Override
public void customize(
Jackson2ObjectMapperBuilder builder) {
builder.serializerByType(Message.class, new JsonSerializer<Message>(){
@Override
public void serialize(Message message, JsonGenerator generator,
SerializerProvider provider) throws IOException {
if(message == null)
return;
JsonJacksonFormat format = new JsonJacksonFormat();
format.print(message, generator);
}});
}
};
}
示例3: testCreateBookInternalServerError
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; //导入依赖的package包/类
@Test
public void testCreateBookInternalServerError() throws Exception {
Book book = buildBook(3L, Currency.EUR, 20.50, Arrays.asList(buildAuthor(1L, toDate("1978-09-25"), null)));
book.setId(null);
when(bookService.createNew(book)).thenThrow(new BookServiceException());
this.mockMvc.perform( post( "/api/books" ).accept( MediaType.parseMediaType( "application/json;charset=UTF-8" ) )
.content(Jackson2ObjectMapperBuilder.json().build().writeValueAsString(book))
.contentType(MediaType.APPLICATION_JSON))
.andDo( print() )
.andExpect( jsonPath("$.code").value("GENERIC_ERROR")) ;
verify(bookService).createNew(book);
}
示例4: setUp
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
mapper = Jackson2ObjectMapperBuilder.json()
.featuresToDisable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.build();
mapper.findAndRegisterModules();
}
示例5: objectMapper
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; //导入依赖的package包/类
private static ObjectMapper objectMapper(Format format) {
ObjectMapper mapper = null;
if (format == Format.YAML) {
mapper = new ObjectMapper(new YAMLFactory());
}
else {
mapper = new ObjectMapper();
}
new Jackson2ObjectMapperBuilder()
.modulesToInstall(new MetadataModule(), new DefaultScalaModule())
.serializationInclusion(JsonInclude.Include.NON_NULL)
.serializationInclusion(JsonInclude.Include.NON_ABSENT)
.serializationInclusion(JsonInclude.Include.NON_EMPTY)
.featuresToEnable(SerializationFeature.INDENT_OUTPUT)
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,
DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE,
DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.configure(mapper);
return mapper;
}
示例6: loadSettings
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; //导入依赖的package包/类
/**
* Load settings from project info file.
*/
public void loadSettings() {
try (FileInputStream fileInput = new FileInputStream(getProjectInfoFile())) {
String projectInfo = FileUtils.readToString(fileInput);
// support legacy build configuration
projectInfo = projectInfo.replaceAll("com\\.consol\\.citrus\\.admin\\.model\\.build\\.maven\\.MavenBuildConfiguration", MavenBuildContext.class.getName());
Project project = Jackson2ObjectMapperBuilder.json().build().readerFor(Project.class).readValue(projectInfo);
setName(project.getName());
setDescription(project.getDescription());
setSettings(project.getSettings());
setVersion(project.getVersion());
} catch (IOException e) {
throw new CitrusRuntimeException("Failed to read project settings file", e);
}
}
示例7: customize
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; //导入依赖的package包/类
@Override
public void customize(Jackson2ObjectMapperBuilder builder) {
if (this.jacksonProperties.getDefaultPropertyInclusion() != null) {
builder.serializationInclusion(
this.jacksonProperties.getDefaultPropertyInclusion());
}
if (this.jacksonProperties.getTimeZone() != null) {
builder.timeZone(this.jacksonProperties.getTimeZone());
}
configureFeatures(builder, this.jacksonProperties.getDeserialization());
configureFeatures(builder, this.jacksonProperties.getSerialization());
configureFeatures(builder, this.jacksonProperties.getMapper());
configureFeatures(builder, this.jacksonProperties.getParser());
configureFeatures(builder, this.jacksonProperties.getGenerator());
configureDateFormat(builder);
configurePropertyNamingStrategy(builder);
configureModules(builder);
configureLocale(builder);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:JacksonAutoConfiguration.java
示例8: configureDateFormat
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; //导入依赖的package包/类
private void configureDateFormat(Jackson2ObjectMapperBuilder builder) {
// We support a fully qualified class name extending DateFormat or a date
// pattern string value
String dateFormat = this.jacksonProperties.getDateFormat();
if (dateFormat != null) {
try {
Class<?> dateFormatClass = ClassUtils.forName(dateFormat, null);
builder.dateFormat(
(DateFormat) BeanUtils.instantiateClass(dateFormatClass));
}
catch (ClassNotFoundException ex) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
dateFormat);
// Since Jackson 2.6.3 we always need to set a TimeZone (see
// gh-4170). If none in our properties fallback to the Jackson's
// default
TimeZone timeZone = this.jacksonProperties.getTimeZone();
if (timeZone == null) {
timeZone = new ObjectMapper().getSerializationConfig()
.getTimeZone();
}
simpleDateFormat.setTimeZone(timeZone);
builder.dateFormat(simpleDateFormat);
}
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:27,代码来源:JacksonAutoConfiguration.java
示例9: configurePropertyNamingStrategy
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; //导入依赖的package包/类
private void configurePropertyNamingStrategy(
Jackson2ObjectMapperBuilder builder) {
// We support a fully qualified class name extending Jackson's
// PropertyNamingStrategy or a string value corresponding to the constant
// names in PropertyNamingStrategy which hold default provided
// implementations
String strategy = this.jacksonProperties.getPropertyNamingStrategy();
if (strategy != null) {
try {
configurePropertyNamingStrategyClass(builder,
ClassUtils.forName(strategy, null));
}
catch (ClassNotFoundException ex) {
configurePropertyNamingStrategyField(builder, strategy);
}
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:JacksonAutoConfiguration.java
示例10: configurePropertyNamingStrategyField
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; //导入依赖的package包/类
private void configurePropertyNamingStrategyField(
Jackson2ObjectMapperBuilder builder, String fieldName) {
// Find the field (this way we automatically support new constants
// that may be added by Jackson in the future)
Field field = ReflectionUtils.findField(PropertyNamingStrategy.class,
fieldName, PropertyNamingStrategy.class);
Assert.notNull(field, "Constant named '" + fieldName + "' not found on "
+ PropertyNamingStrategy.class.getName());
try {
builder.propertyNamingStrategy(
(PropertyNamingStrategy) field.get(null));
}
catch (Exception ex) {
throw new IllegalStateException(ex);
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:JacksonAutoConfiguration.java
示例11: objectMapperBuilder
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; //导入依赖的package包/类
@Bean
public Jackson2ObjectMapperBuilder objectMapperBuilder(JsonComponentModule jsonComponentModule) {
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
builder
// .serializerByType(ZonedDateTime.class, new JsonSerializer<ZonedDateTime>() {
// @Override
// public void serialize(ZonedDateTime zonedDateTime, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
// jsonGenerator.writeString(DateTimeFormatter.ISO_ZONED_DATE_TIME.format(zonedDateTime));
// }
// })
.serializationInclusion(JsonInclude.Include.NON_EMPTY)
.featuresToDisable(
SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,
DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES,
DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
)
.featuresToEnable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
.indentOutput(true)
.modulesToInstall(jsonComponentModule);
return builder;
}
示例12: jacksonObjectMapperBuilder
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(Jackson2ObjectMapperBuilder.class)
public Jackson2ObjectMapperBuilder jacksonObjectMapperBuilder() {
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
builder.applicationContext(this.applicationContext);
if (this.jacksonProperties.getSerializationInclusion() != null) {
builder.serializationInclusion(
this.jacksonProperties.getSerializationInclusion());
}
if (this.jacksonProperties.getTimeZone() != null) {
builder.timeZone(this.jacksonProperties.getTimeZone());
}
configureFeatures(builder, this.jacksonProperties.getDeserialization());
configureFeatures(builder, this.jacksonProperties.getSerialization());
configureFeatures(builder, this.jacksonProperties.getMapper());
configureFeatures(builder, this.jacksonProperties.getParser());
configureFeatures(builder, this.jacksonProperties.getGenerator());
configureDateFormat(builder);
configurePropertyNamingStrategy(builder);
configureModules(builder);
configureLocale(builder);
return builder;
}
示例13: configurePropertyNamingStrategy
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; //导入依赖的package包/类
private void configurePropertyNamingStrategy(
Jackson2ObjectMapperBuilder builder) {
// We support a fully qualified class name extending Jackson's
// PropertyNamingStrategy or a string value corresponding to the constant
// names in PropertyNamingStrategy which hold default provided implementations
String strategy = this.jacksonProperties.getPropertyNamingStrategy();
if (strategy != null) {
try {
configurePropertyNamingStrategyClass(builder,
ClassUtils.forName(strategy, null));
}
catch (ClassNotFoundException ex) {
configurePropertyNamingStrategyField(builder, strategy);
}
}
}
示例14: defaultObjectMapperBuilder
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; //导入依赖的package包/类
@Test
public void defaultObjectMapperBuilder() throws Exception {
this.context.register(JacksonAutoConfiguration.class);
this.context.refresh();
Jackson2ObjectMapperBuilder builder = this.context
.getBean(Jackson2ObjectMapperBuilder.class);
ObjectMapper mapper = builder.build();
assertTrue(MapperFeature.DEFAULT_VIEW_INCLUSION.enabledByDefault());
assertFalse(mapper.getDeserializationConfig()
.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
assertTrue(MapperFeature.DEFAULT_VIEW_INCLUSION.enabledByDefault());
assertFalse(mapper.getDeserializationConfig()
.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
assertFalse(mapper.getSerializationConfig()
.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
assertTrue(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES.enabledByDefault());
assertFalse(mapper.getDeserializationConfig()
.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
}
示例15: jackson2ObjectMapperBuilder
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; //导入依赖的package包/类
@Bean
Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() {
JavaTimeModule module = new JavaTimeModule();
module.addSerializer(OffsetDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(ZonedDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(LocalDateTime.class, JSR310DateTimeSerializer.INSTANCE);
module.addSerializer(Instant.class, JSR310DateTimeSerializer.INSTANCE);
module.addDeserializer(LocalDate.class, JSR310LocalDateDeserializer.INSTANCE);
return new Jackson2ObjectMapperBuilder()
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.serializationInclusion(JsonInclude.Include.NON_NULL)
.findModulesViaServiceLoader(true)
//.featuresToEnable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING)
//.featuresToEnable(DeserializationFeature.READ_ENUMS_USING_TO_STRING)
.modulesToInstall(module);
}