本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例13: JsonIoPlugin
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public JsonIoPlugin() {
mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
}
示例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;
}
示例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;
}