當前位置: 首頁>>代碼示例>>Java>>正文


Java ObjectMapper.setSerializationInclusion方法代碼示例

本文整理匯總了Java中com.fasterxml.jackson.databind.ObjectMapper.setSerializationInclusion方法的典型用法代碼示例。如果您正苦於以下問題:Java ObjectMapper.setSerializationInclusion方法的具體用法?Java ObjectMapper.setSerializationInclusion怎麽用?Java ObjectMapper.setSerializationInclusion使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.fasterxml.jackson.databind.ObjectMapper的用法示例。


在下文中一共展示了ObjectMapper.setSerializationInclusion方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: serialize

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
@Override
public String serialize(Object entity) throws HttpException {
    String json = null;
    
    try {
        
        ObjectMapper mapper = new ObjectMapper();            
        mapper.setSerializationInclusion(Include.NON_NULL);
        mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
        
        json = mapper.writeValueAsString(entity);   
        
    } catch (JsonProcessingException e) {           
        throw new InternalServerErrorException(e.getMessage(), e);      
    }
    
    return json;
}
 
開發者ID:tdsis,項目名稱:lambda-forest,代碼行數:19,代碼來源:JsonResponseBodySerializerStrategy.java

示例2: initializeObjectMapper

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
@Override
protected ObjectMapper initializeObjectMapper() {
    final ObjectMapper mapper = super.initializeObjectMapper();

    final FilterProvider filters = new SimpleFilterProvider()
            .addFilter("beanObjectFilter", new CasSimpleBeanObjectFilter());
    mapper.setFilters(filters);

    mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
    mapper.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false);
    mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.addMixIn(Object.class, CasSimpleBeanObjectFilter.class);
    mapper.disable(SerializationFeature.INDENT_OUTPUT);
    mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);

    return mapper;
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:20,代碼來源:InternalConfigStateController.java

示例3: convertObjectToJsonBytes

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
/**
 * Convert an object to JSON byte array.
 *
 * @param object
 *            the object to convert
 * @return the JSON byte array
 * @throws IOException
 */
public static byte[] convertObjectToJsonBytes(Object object)
        throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    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);
    mapper.registerModule(module);

    return mapper.writeValueAsBytes(object);
}
 
開發者ID:klask-io,項目名稱:klask-io,代碼行數:24,代碼來源:TestUtil.java

示例4: convertObjectToJsonBytes

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
/**
 * Convert an object to JSON byte array.
 *
 * @param object
 *            the object to convert
 * @return the JSON byte array
 * @throws IOException
 */
public static byte[] convertObjectToJsonBytes(Object object)
        throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    JavaTimeModule module = new JavaTimeModule();
    mapper.registerModule(module);

    return mapper.writeValueAsBytes(object);
}
 
開發者ID:asanzdiego,項目名稱:codemotion-2017-taller-de-jhipster,代碼行數:19,代碼來源:TestUtil.java

示例5: getObjectMapper

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
/**
 * get ObjectMapper entity.
 * @param flag configure
 * @param incl setSerializationInclusion
 * @return ObjectMapper entity
 */
public static ObjectMapper getObjectMapper(boolean flag, Include incl) {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
                       flag);
    objectMapper.setSerializationInclusion(incl);
    return objectMapper;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:15,代碼來源:ObjectMapperUtil.java

示例6: createDefaultObjectMapper

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
private static ObjectMapper createDefaultObjectMapper() {
    final ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    objectMapper.registerModules(new Jdk8Module(), new ParameterNamesModule(), new JavaTimeModule());
    objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    return objectMapper;
}
 
開發者ID:zalando-nakadi,項目名稱:nakadi-producer-spring-boot-starter,代碼行數:9,代碼來源:MockNakadiPublishingClient.java

示例7: initializeObjectMapper

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
/**
 * Initialize object mapper.
 *
 * @return the object mapper
 */
protected ObjectMapper initializeObjectMapper() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    mapper.setVisibility(PropertyAccessor.SETTER, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC);
    mapper.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC);
    mapper.setVisibility(PropertyAccessor.IS_GETTER, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC);
    mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
    return mapper;
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:16,代碼來源:AbstractJacksonBackedJsonSerializer.java

示例8: configureObjectMapper

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
/**
 * Configure mapper.
 *
 * @param mapper the mapper
 */
protected void configureObjectMapper(final ObjectMapper mapper) {
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    mapper.setVisibility(PropertyAccessor.SETTER, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC);
    mapper.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC);
    mapper.setVisibility(PropertyAccessor.IS_GETTER, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC);

    if (isDefaultTypingEnabled()) {
        mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
    }
    mapper.findAndRegisterModules();
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:20,代碼來源:AbstractJacksonBackedStringSerializer.java

示例9: provideObjectMapper

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
@Provides
@Singleton
ObjectMapper provideObjectMapper() {
  ObjectMapper objectMapper = new ObjectMapper();

  objectMapper.setPropertyNamingStrategy(
      PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
  objectMapper.setSerializationInclusion(JsonInclude.Include.NON_ABSENT);
  objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
  objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

  return objectMapper;
}
 
開發者ID:cerner,項目名稱:beadledom,代碼行數:14,代碼來源:FauxModule.java

示例10: convertObjectToJson

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
public static String convertObjectToJson(Object object) throws IOException {
	ObjectMapper mapper = new ObjectMapper();
	mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
	String json = mapper.writeValueAsString(object);
	return json;
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-skipper,代碼行數:7,代碼來源:AbstractMockMvcTests.java

示例11: CloudJacksonCodec

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
public CloudJacksonCodec() {
	super();

	ObjectMapper mapper = new ObjectMapper();
	mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

	SimpleModule module = new SimpleModule("eureka1.x", VERSION);
	module.addSerializer(DataCenterInfo.class, new DataCenterInfoSerializer());
	module.addSerializer(InstanceInfo.class, new CloudInstanceInfoSerializer());
	module.addSerializer(Application.class, new ApplicationSerializer());
	module.addSerializer(Applications.class, new ApplicationsSerializer(
			this.getVersionDeltaKey(), this.getAppHashCodeKey()));

	module.addDeserializer(DataCenterInfo.class,
			new DataCenterInfoDeserializer());
	module.addDeserializer(LeaseInfo.class, new LeaseInfoDeserializer());
	module.addDeserializer(InstanceInfo.class,
			new CloudInstanceInfoDeserializer(mapper));
	module.addDeserializer(Application.class,
			new ApplicationDeserializer(mapper));
	module.addDeserializer(Applications.class, new ApplicationsDeserializer(
			mapper, this.getVersionDeltaKey(), this.getAppHashCodeKey()));

	mapper.registerModule(module);

	HashMap<Class<?>, ObjectReader> readers = new HashMap<>();
	readers.put(InstanceInfo.class, mapper.reader().withType(InstanceInfo.class)
			.withRootName("instance"));
	readers.put(Application.class, mapper.reader().withType(Application.class)
			.withRootName("application"));
	readers.put(Applications.class, mapper.reader().withType(Applications.class)
			.withRootName("applications"));
	setField("objectReaderByClass", readers);

	HashMap<Class<?>, ObjectWriter> writers = new HashMap<>();
	writers.put(InstanceInfo.class, mapper.writer().withType(InstanceInfo.class)
			.withRootName("instance"));
	writers.put(Application.class, mapper.writer().withType(Application.class)
			.withRootName("application"));
	writers.put(Applications.class, mapper.writer().withType(Applications.class)
			.withRootName("applications"));
	setField("objectWriterByClass", writers);

	setField("mapper", mapper);
}
 
開發者ID:dyc87112,項目名稱:didi-eureka-server,代碼行數:47,代碼來源:CloudJacksonJson.java

示例12: createYamlObjectMapper

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
public static ObjectMapper createYamlObjectMapper() {
    ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    return objectMapper;
}
 
開發者ID:membrane,項目名稱:kubernetes-client,代碼行數:6,代碼來源:KubernetesHelper.java

示例13: JsonIoPlugin

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
public JsonIoPlugin() {
    mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
}
 
開發者ID:jonfryd,項目名稱:tifoon,代碼行數:5,代碼來源:JsonIoPlugin.java

示例14: getDefaultObjectMapper

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
static ObjectMapper getDefaultObjectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    return mapper;
}
 
開發者ID:GJWT,項目名稱:javaOIDCMsg,代碼行數:7,代碼來源:JWTParser.java

示例15: createObjectMapper

import com.fasterxml.jackson.databind.ObjectMapper; //導入方法依賴的package包/類
private static ObjectMapper createObjectMapper() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    SimpleClassNameIdResolver.configureObjectMapper(mapper);
    return mapper;
}
 
開發者ID:gchq,項目名稱:koryphe,代碼行數:7,代碼來源:JsonSerialiser.java


注:本文中的com.fasterxml.jackson.databind.ObjectMapper.setSerializationInclusion方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。