本文整理汇总了Java中com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion类的典型用法代码示例。如果您正苦于以下问题:Java Inclusion类的具体用法?Java Inclusion怎么用?Java Inclusion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Inclusion类属于com.fasterxml.jackson.databind.annotation.JsonSerialize包,在下文中一共展示了Inclusion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: JsonMapper
import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion; //导入依赖的package包/类
public JsonMapper(Inclusion inclusion, DateFormat df, boolean replaceNull)
{
mapper = new ObjectMapper();
// 设置输出时包含属性的风格
// mapper.setSerializationInclusion(inclusion);
// // 设置输入时忽略在JSON字符串中存在但Java对象实际没有的属性
// mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// // 禁止使用int代表Enum的order()來反序列化Enum
// mapper.configure(DeserializationConfig.Feature.FAIL_ON_NUMBERS_FOR_ENUMS, true);
// 允许单引号
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
mapper.setDateFormat(df);
if (replaceNull) {
// null 转换为 ""
mapper.getSerializerProvider().setNullValueSerializer(new JsonSerializer<Object>()
{
@Override
public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException
{
jgen.writeString("");
}
});
}
}
示例2: getId
import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion; //导入依赖的package包/类
@JsonSerialize(include = Inclusion.NON_NULL)
public UUID getId() {
if ( id != null ) {
return id;
}
if ( entity != null ) {
id = entity.getUuid();
return id;
}
if ( ( ids != null ) && ( ids.size() > 0 ) ) {
id = ids.get( 0 );
return id;
}
if ( ( entities != null ) && ( entities.size() > 0 ) ) {
entity = entities.get( 0 );
id = entity.getUuid();
return id;
}
if ( ( refs != null ) && ( refs.size() > 0 ) ) {
EntityRef ref = refs.get( 0 );
id = ref.getUuid();
}
return id;
}
示例3: getRef
import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion; //导入依赖的package包/类
@JsonSerialize(include = Inclusion.NON_NULL)
public EntityRef getRef() {
if ( ref != null ) {
return ref;
}
ref = getEntity();
if ( ref != null ) {
return ref;
}
UUID u = getId();
if ( u != null ) {
String type= null;
if(refs!=null && refs.size()>0){
type = refs.get(0).getType();
}
return ref( type,u );
}
return null;
}
示例4: success
import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion; //导入依赖的package包/类
/**
* 返回日期处理成功结果
* @param data 数据节点对象
* @return JSON结果
*/
public static String success(Object data, String format)
{
Map<String, Object> map = new HashMap<String, Object>();
map.put("code", GlobalResultStatus.SUCCESS.getCode());
if (data != null)
{
map.put("data", data);
}
JsonMapper mapper = new JsonMapper(Inclusion.NON_NULL, new SimpleDateFormat(format));
return mapper.toJson(map);
}
示例5: valueAllowed
import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion; //导入依赖的package包/类
boolean valueAllowed(Object value, Class cls) {
return value != null
|| (serializerProvider.getConfig() != null
&& serializerProvider.getConfig().getSerializationInclusion() == Include.ALWAYS
&& getAnnotation(cls, JsonSerialize.class) == null)
|| (getAnnotation(cls, JsonSerialize.class) != null
&& readClassAnnotation(cls, JsonSerialize.class, "include") == Inclusion.ALWAYS);
}
示例6: toJson
import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion; //导入依赖的package包/类
/**
* 将对象转换成json, 可以设置输出属性
*
*
* @param src 对象
* @param inclusion 传入一个枚举值, 设置输出属性
* @return 返回json字符串
*/
public static <T> String toJson(T src, Inclusion inclusion) {
if (src instanceof String) {
return (String) src;
} else {
ObjectMapper customMapper = generateMapper(inclusion);
try {
return customMapper.writeValueAsString(src);
} catch (JsonProcessingException e) {
LOG.error("JsonProcessingException: ", e);
}
}
return null;
}
示例7: generateMapper
import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion; //导入依赖的package包/类
/**
* 通过Inclusion创建ObjectMapper对象
*
*
* @param inclusion 传入一个枚举值, 设置输出属性
* @return 返回ObjectMapper对象
*/
private static ObjectMapper generateMapper(Inclusion inclusion) {
ObjectMapper customMapper = new ObjectMapper();
// 所有日期格式都统一为以下样式
customMapper.setDateFormat(new SimpleDateFormat(DATE_TIME_FORMAT));
return customMapper;
}
示例8: getEntity
import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion; //导入依赖的package包/类
@JsonSerialize(include = Inclusion.NON_NULL)
public Entity getEntity() {
mergeEntitiesWithMetadata();
if ( entity != null ) {
return entity;
}
if ( ( entities != null ) && ( entities.size() > 0 ) ) {
entity = entities.get( 0 );
return entity;
}
return null;
}
示例9: getEntitiesMap
import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion; //导入依赖的package包/类
@JsonSerialize(include = Inclusion.NON_NULL)
public Map<UUID, Entity> getEntitiesMap() {
if ( entitiesMap != null ) {
return entitiesMap;
}
if ( getEntities() != null ) {
entitiesMap = new LinkedHashMap<UUID, Entity>();
for ( Entity entity : getEntities() ) {
entitiesMap.put( entity.getUuid(), entity );
}
}
return entitiesMap;
}
示例10: buildNormalMapper
import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion; //导入依赖的package包/类
/**
* 创建输出全部属性到Json字符串的Mapper.
*/
public static JsonMapper buildNormalMapper()
{
return new JsonMapper(Inclusion.ALWAYS);
}
示例11: buildNonNullMapper
import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion; //导入依赖的package包/类
/**
* 创建只输出非空属性到Json字符串的Mapper.
*/
public static JsonMapper buildNonNullMapper()
{
return new JsonMapper(Inclusion.NON_NULL);
}
示例12: buildNonDefaultMapper
import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion; //导入依赖的package包/类
/**
* 创建只输出初始值被改变的属性到Json字符串的Mapper.
*/
public static JsonMapper buildNonDefaultMapper()
{
return new JsonMapper(Inclusion.NON_DEFAULT);
}
示例13: buildNonEmptyMapper
import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion; //导入依赖的package包/类
/**
* 创建只输出非Null且非Empty(如List.isEmpty)的属性到Json字符串的Mapper.
*/
public static JsonMapper buildNonEmptyMapper()
{
return new JsonMapper(Inclusion.NON_EMPTY);
}
示例14: reportSuccess
import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion; //导入依赖的package包/类
/**
* 报表返回格式日期处理成功结果
* @param data 数据节点对象
* @return JSON结果
*/
public static String reportSuccess(Object data, String format)
{
JsonMapper mapper = new JsonMapper(Inclusion.NON_NULL, new SimpleDateFormat(format));
return mapper.toJson(data);
}
示例15: getAccessToken
import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion; //导入依赖的package包/类
/**
* Returns the OAuth token that was sent with the request
*
* @return the OAuth token
*/
@JsonProperty("access_token")
@JsonSerialize(include = Inclusion.NON_NULL)
public String getAccessToken() {
return accessToken;
}