适配TinyInt

This commit is contained in:
liangdaliang
2025-03-07 15:02:59 +08:00
parent 9540e8924e
commit ebc090c437
2 changed files with 15 additions and 17 deletions

View File

@@ -11,21 +11,18 @@ import java.io.IOException;
* @Description
* @date 2025-03-07 13:32
*/
public class TinyIntTypeAdapter extends TypeAdapter<Number> {
public class TinyIntTypeAdapter extends TypeAdapter<Byte> {
@Override
public void write(JsonWriter out, Number value) throws IOException {
public void write(JsonWriter out, Byte value) throws IOException {
if (value == null) {
out.nullValue();
} else {
out.value(value.intValue()); // 强制转换为整数
out.value(value.intValue());
}
}
@Override
public Number read(JsonReader in) throws IOException {
if (in.peek() == null) {
return null;
}
return in.nextInt(); // 读取为整数
public Byte read(JsonReader in) throws IOException {
throw new UnsupportedOperationException("Unreadable");
}
}