当前位置: 首页>>代码示例>>Java>>正文


Java Jackson2ObjectMapperBuilder类代码示例

本文整理汇总了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();
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:21,代码来源:JacksonAutoConfigurationTests.java

示例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);
				}});
			
		}
	};
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:22,代码来源:ProtobufConfiguration.java

示例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);
}
 
开发者ID:lucamartellucci,项目名称:bookshop-api,代码行数:17,代码来源:BookControllerTest.java

示例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();
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:9,代码来源:DefaultAuthenticationTests.java

示例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;
}
 
开发者ID:atomist-attic,项目名称:rug-resolver,代码行数:21,代码来源:MetadataWriter.java

示例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);
    }
}
 
开发者ID:christophd,项目名称:citrus-admin,代码行数:21,代码来源:Project.java

示例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;
}
 
开发者ID:hantsy,项目名称:angularjs-springmvc-sample-boot,代码行数:24,代码来源:Jackson2ObjectMapperConfig.java

示例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;
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:24,代码来源:JacksonAutoConfiguration.java

示例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);
		}
	}
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:17,代码来源:JacksonAutoConfiguration.java

示例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));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:20,代码来源:JacksonAutoConfigurationTests.java

示例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);
}
 
开发者ID:esutoniagodesu,项目名称:egd-web,代码行数:18,代码来源:JacksonConfiguration.java


注:本文中的org.springframework.http.converter.json.Jackson2ObjectMapperBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。