AdmConfig.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package com.persagy.bdtp.adm.entity;
  2. import cn.hutool.core.util.StrUtil;
  3. import com.baomidou.mybatisplus.annotation.TableField;
  4. import com.baomidou.mybatisplus.annotation.TableName;
  5. import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
  6. import com.fasterxml.jackson.core.JsonProcessingException;
  7. import com.fasterxml.jackson.databind.JsonNode;
  8. import com.fasterxml.jackson.databind.ObjectMapper;
  9. import com.fasterxml.jackson.databind.node.ObjectNode;
  10. import com.persagy.dmp.common.helper.SpringHelper;
  11. import lombok.Data;
  12. import java.io.IOException;
  13. @Data
  14. @TableName(value = "adm_config",autoResultMap = true)
  15. public class AdmConfig implements IAdmEntity {
  16. private String id;
  17. private String projectId;
  18. private String name;
  19. private String code;
  20. @TableField(
  21. typeHandler = JacksonTypeHandler.class
  22. )
  23. private JsonNode data;
  24. private String strData;
  25. @Override
  26. public void serializeJsonProp() {
  27. if(data != null) {
  28. ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
  29. try {
  30. strData = objectMapper.writeValueAsString(data);
  31. } catch (JsonProcessingException e) {
  32. }
  33. data = null;
  34. }
  35. }
  36. @Override
  37. public void deserializeJsonProp() {
  38. if(StrUtil.isNotBlank(strData)) {
  39. ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
  40. try {
  41. data = objectMapper.readValue(strData, JsonNode.class);
  42. } catch (IOException e) {
  43. }
  44. strData = null;
  45. }
  46. }
  47. }