feat(material): 更新物料信息响应DTO的JSON序列化配置,解决问题使用id调用feign接口查询返回为null的问题,任务id690
- 为ID、编码、名称、分类ID、备注和创建时间字段添加JsonProperty注解 - 将flatAttributes字段初始化为LinkedHashMap以保证顺序 - 添加JsonAnySetter注解和addAttribute方法处理动态属性 - 移除原flatAttributes字段的序列化展开说明
This commit is contained in:
@@ -1,11 +1,14 @@
|
|||||||
package com.zt.plat.module.base.api.materialinfomation.dto;
|
package com.zt.plat.module.base.api.materialinfomation.dto;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonAnyGetter;
|
import com.fasterxml.jackson.annotation.JsonAnyGetter;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -14,36 +17,44 @@ import java.util.Map;
|
|||||||
@Data
|
@Data
|
||||||
public class MaterialInfomationRespDTO {
|
public class MaterialInfomationRespDTO {
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "3326")
|
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "3326")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||||
@Schema(description = "物料编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "物料编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
private String code;
|
private String code;
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||||
@Schema(description = "物料名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
|
@Schema(description = "物料名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||||
@Schema(description = "分类ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
@Schema(description = "分类ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||||
private Long classesId;
|
private Long classesId;
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||||
@Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
private String remark;
|
private String remark;
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
@Schema(description = "物料基础字段 + 属性编码->原值的动态键值,基础字段优先,序列化时直接展开为顶层字段")
|
@Schema(description = "物料基础字段 + 属性编码->原值的动态键值")
|
||||||
private Map<String, Object> flatAttributes;
|
private Map<String, Object> flatAttributes = new LinkedHashMap<>();
|
||||||
|
|
||||||
@JsonAnyGetter
|
@JsonAnyGetter
|
||||||
public Map<String, Object> getFlatAttributes() {
|
public Map<String, Object> getFlatAttributes() {
|
||||||
return flatAttributes;
|
return flatAttributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonAnySetter
|
||||||
|
public void addAttribute(String key, Object value) {
|
||||||
|
if (flatAttributes == null) {
|
||||||
|
flatAttributes = new LinkedHashMap<>();
|
||||||
|
}
|
||||||
|
flatAttributes.put(key, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user