增加工作流代码可正常启动
This commit is contained in:
parent
ac4626e0c3
commit
80ddeb0ecb
@ -0,0 +1,45 @@
|
|||||||
|
package com.qqchen.deploy.backend.workflow.converter;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import jakarta.persistence.AttributeConverter;
|
||||||
|
import jakarta.persistence.Converter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JSON对象转换器
|
||||||
|
* 用于在数据库字符串和Java对象之间进行转换
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Converter
|
||||||
|
public class JsonObjectConverter implements AttributeConverter<Object, String> {
|
||||||
|
|
||||||
|
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String convertToDatabaseColumn(Object attribute) {
|
||||||
|
if (attribute == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return objectMapper.writeValueAsString(attribute);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
log.error("Error converting object to json string", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object convertToEntityAttribute(String dbData) {
|
||||||
|
if (!StringUtils.hasText(dbData)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return objectMapper.readValue(dbData, Object.class);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
log.error("Error converting json string to object", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user