REQ-2135: ignore empty field when parse and serialize JSON
This commit is contained in:
parent
88387add9b
commit
949e547a37
@ -1,6 +1,7 @@
|
||||
package cn.axzo.msg.center.domain.entity;
|
||||
|
||||
import cn.axzo.msg.center.domain.persistence.BaseEntityExt;
|
||||
import cn.axzo.msg.center.domain.utils.IgnoreEmptyFieldJsonTypeHandler;
|
||||
import cn.axzo.msg.center.service.enums.IdentityTypeEnum;
|
||||
import cn.axzo.msg.center.service.enums.OrganizationTypeEnum;
|
||||
import cn.axzo.msg.center.service.enums.PendingMessageStateEnum;
|
||||
@ -10,7 +11,6 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@ -112,13 +112,13 @@ public class Todo extends BaseEntityExt<Todo> {
|
||||
/**
|
||||
* 业务扩展参数
|
||||
*/
|
||||
@TableField(typeHandler = FastjsonTypeHandler.class)
|
||||
@TableField(typeHandler = IgnoreEmptyFieldJsonTypeHandler.class)
|
||||
private JSONObject bizExtParam;
|
||||
|
||||
/**
|
||||
* 路由参数
|
||||
*/
|
||||
@TableField(typeHandler = FastjsonTypeHandler.class)
|
||||
@TableField(typeHandler = IgnoreEmptyFieldJsonTypeHandler.class)
|
||||
private JSONObject routerParams;
|
||||
|
||||
/**
|
||||
@ -149,7 +149,7 @@ public class Todo extends BaseEntityExt<Todo> {
|
||||
/**
|
||||
* 保存额外的数据信息
|
||||
*/
|
||||
@TableField(typeHandler = FastjsonTypeHandler.class)
|
||||
@TableField(typeHandler = IgnoreEmptyFieldJsonTypeHandler.class)
|
||||
private PendingRecordExt recordExt = new PendingRecordExt();
|
||||
|
||||
// !! helper
|
||||
|
||||
@ -1,15 +1,14 @@
|
||||
package cn.axzo.msg.center.domain.entity;
|
||||
|
||||
import cn.axzo.msg.center.domain.persistence.BaseEntityExt;
|
||||
import cn.axzo.msg.center.domain.utils.IgnoreEmptyFieldJsonTypeHandler;
|
||||
import cn.axzo.msg.center.service.enums.BizCategoryEnum;
|
||||
import cn.axzo.msg.center.service.enums.BizFinalStateEnum;
|
||||
import cn.axzo.msg.center.service.enums.IdentityTypeEnum;
|
||||
import cn.axzo.msg.center.service.enums.OrganizationTypeEnum;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@ -86,13 +85,13 @@ public class TodoBusiness extends BaseEntityExt<TodoBusiness> {
|
||||
/**
|
||||
* 业务扩展参数
|
||||
*/
|
||||
@TableField(typeHandler = FastjsonTypeHandler.class)
|
||||
@TableField(typeHandler = IgnoreEmptyFieldJsonTypeHandler.class)
|
||||
private JSONObject bizExtParam;
|
||||
|
||||
/**
|
||||
* 路由参数
|
||||
*/
|
||||
@TableField(typeHandler = FastjsonTypeHandler.class)
|
||||
@TableField(typeHandler = IgnoreEmptyFieldJsonTypeHandler.class)
|
||||
private JSONObject routerParams;
|
||||
|
||||
/**
|
||||
@ -118,7 +117,7 @@ public class TodoBusiness extends BaseEntityExt<TodoBusiness> {
|
||||
/**
|
||||
* 保存额外的数据信息
|
||||
*/
|
||||
@TableField(typeHandler = FastjsonTypeHandler.class)
|
||||
@TableField(typeHandler = IgnoreEmptyFieldJsonTypeHandler.class)
|
||||
private TodoBusinessExt recordExt = new TodoBusinessExt();
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
package cn.axzo.msg.center.domain.entity;
|
||||
|
||||
import cn.axzo.msg.center.domain.persistence.BaseEntityExt;
|
||||
import cn.axzo.msg.center.domain.utils.IgnoreEmptyFieldJsonTypeHandler;
|
||||
import cn.axzo.msg.center.service.enums.TodoLogType;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@ -57,13 +57,13 @@ public class TodoLog extends BaseEntityExt<TodoLog> {
|
||||
/**
|
||||
* 关键变化
|
||||
*/
|
||||
@TableField(typeHandler = FastjsonTypeHandler.class)
|
||||
@TableField(typeHandler = IgnoreEmptyFieldJsonTypeHandler.class)
|
||||
private JSONObject logContent;
|
||||
|
||||
/**
|
||||
* 额外信息
|
||||
*/
|
||||
@TableField(typeHandler = FastjsonTypeHandler.class)
|
||||
@TableField(typeHandler = IgnoreEmptyFieldJsonTypeHandler.class)
|
||||
private JSONObject recordExt;
|
||||
|
||||
/**
|
||||
|
||||
@ -0,0 +1,32 @@
|
||||
package cn.axzo.msg.center.domain.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.MappedJdbcTypes;
|
||||
import org.apache.ibatis.type.MappedTypes;
|
||||
|
||||
/**
|
||||
* @author yanglin
|
||||
*/
|
||||
@Slf4j
|
||||
@MappedTypes({Object.class})
|
||||
@MappedJdbcTypes(JdbcType.VARCHAR)
|
||||
@RequiredArgsConstructor
|
||||
public class IgnoreEmptyFieldJsonTypeHandler extends AbstractJsonTypeHandler<Object> {
|
||||
|
||||
private final Class<?> type;
|
||||
|
||||
@Override
|
||||
protected Object parse(String json) {
|
||||
return JSON.parseObject(json, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toJson(Object obj) {
|
||||
return JSON.toJSONString(obj);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user