sql执行tinyInt字段适配
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package com.test.common.utils.sql;
|
||||
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author liangdaliang
|
||||
* @Description:
|
||||
* @date 2025-03-07 13:32
|
||||
*/
|
||||
public class TinyIntTypeAdapter extends TypeAdapter<Number> {
|
||||
@Override
|
||||
public void write(JsonWriter out, Number value) throws IOException {
|
||||
if (value == null) {
|
||||
out.nullValue();
|
||||
} else {
|
||||
out.value(value.intValue()); // 强制转换为整数
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number read(JsonReader in) throws IOException {
|
||||
if (in.peek() == null) {
|
||||
return null;
|
||||
}
|
||||
return in.nextInt(); // 读取为整数
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user