fix:解决oracle数据库的TIMESTAMP类型数据序列化失败问题
parent
3d99d17acb
commit
da63bc31cd
@ -0,0 +1,42 @@
|
|||||||
|
package com.gccloud.dataroom.core.config;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||||
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import oracle.sql.TIMESTAMP;
|
||||||
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解决oracle TIMESTAMP类型返回序列化问题
|
||||||
|
* @author hongyang
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2024/05/07 10:30
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class OracleTimestampSerializer extends JsonSerializer<TIMESTAMP> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(TIMESTAMP timestamp, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
|
||||||
|
jsonGenerator.writeString(timestampToString(timestamp));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* timestamp字段处理
|
||||||
|
*
|
||||||
|
* @param timestamp
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String timestampToString(TIMESTAMP timestamp) {
|
||||||
|
String content = "";
|
||||||
|
try {
|
||||||
|
// 转为日期格式
|
||||||
|
content = timestamp.stringValue();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(ExceptionUtils.getStackTrace(e));
|
||||||
|
}
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue