apache / apache/incubator-seata

Jpa in jackson serialization oracle.timestamp type error or garbled problem

Open
#1,384 1 comment 0 reactions 0 assignees View on GitHub
DB: Oracle type: bug type: question
Dominant language
Java
Stars
26k
Forks
8.8k
Avg merge
1d 8h
Merged PRs (30d)
4

Description

- [ ] I have searched the [issues](https://github.com/seata/seata/issues) of this repository and believe that this is not a duplicate.

### Ⅰ. Issue Description
在jpa使用中jackson序列化时间出错或者乱码问题时,需要在
bom/pom文件中新增
```

com.fasterxml.jackson.datatype
jackson-datatype-hibernate5
${jackson.version}


com.fasterxml.jackson.datatype
jackson-datatype-hppc
${jackson.version}


com.fasterxml.jackson.datatype
jackson-datatype-jsr310
${jackson.version}


com.fasterxml.jackson.module
jackson-module-afterburner
${jackson.version}

```
2.在rm-datasource中的pom文件新增:
```

com.fasterxml.jackson.datatype
jackson-datatype-hibernate5


com.fasterxml.jackson.datatype
jackson-datatype-hppc


com.fasterxml.jackson.datatype
jackson-datatype-jsr310


com.fasterxml.jackson.module
jackson-module-afterburner

```
3.在rm-datasource的pom文件中新增oracle驱动这里用本地驱动代替
```

com.oracle
ojdbc8
18.3.0.0
system
${basedir}/src/main/lib/ojdbc8-18.3.0.0.jar

```
4.添加完成后在rm-datasource中rm-datasource\src\main\java\io\seata\rm\datasource\undo\parser\JacksonUndoLogParser.java文件s中static改造如下:
```
static {
MAPPER.registerModule(new JavaTimeModule());
MAPPER.registerModule(new Hibernate5Module());
MAPPER.configure(JsonGenerator.Feature.ESCAPE_NON_ASCII, true);
MAPPER.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
MAPPER.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
}
```
5.在rm-datasource\src\main\java\io\seata\rm\datasource\sql\struct\TableRecords.java中修改一下字段获取类型针对获取oracle.TIMESTAMP做一个判断取值,修改buildRecords方法如下:
```
/**
* Build records table records.
*
* @param tmeta the tmeta
* @param resultSet the result set
* @return the table records
* @throws SQLException the sql exception
*/
public static TableRecords buildRecords(TableMeta tmeta, ResultSet resultSet) throws SQLException {
TableRecords records = new TableRecords(tmeta);
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
int columnCount = resultSetMetaData.getColumnCount();

while (resultSet.next()) {
List fields = new ArrayList<>(columnCount);
for (int i = 1; i <= columnCount; i++) {
String colName = resultSetMetaData.getColumnName(i);
ColumnMeta col = tmeta.getColumnMeta(colName);
Field field = new Field();
field.setName(col.getColumnName());
if (tmeta.getPkName().equals(field.getName())) {
field.setKeyType(KeyType.PrimaryKey);
}
field.setType(col.getDataType());
Object object = resultSet.getObject(i);
if (col.getDataType() == Types.TIMESTAMP) {#这里新增判断属于oracle.timestamp类型
TIMESTAMP timestamp = (TIMESTAMP) object;
field.setValue(timestamp == null ? null : timestamp.timestampValue());#获取时间值用与jackson序列化
} else {
field.setValue(object);
}

fields.add(field);
}

Row row = new Row();
row.setFields(fields);

records.add(row);
}
return records;
}
```
### Ⅱ. Describe what happened

If there is an exception, please attach the exception trace:

```
Just paste your stack trace here!
```

### Ⅲ. Describe what you expected to happen

### Ⅳ. How to reproduce it (as minimally and precisely as possible)

1. xxx
2. xxx
3. xxx

### Ⅴ. Anything else we need to know?

### Ⅵ. Environment:

- JDK version : jdk8
- OS : docker
- Others: ojdbc8-18.3.0.0

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the dependency changes requested in the bom/pom files and rm-datasource/pom. Then inspect rm-datasource/src/main/java/io/seata/rm/datasource/undo/parser/JacksonUndoLogParser.java and rm-datasource/src/main/java/io/seata/rm/datasource/sql/struct/TableRecords.java, reproducing with JDK 8, Docker, and ojdbc8. Done means Oracle TIMESTAMP values serialize without errors or garbling.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
18/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.