Skip to content

Commit 52b93a7

Browse files
committed
refactor: 优化
1 parent 50cf4eb commit 52b93a7

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/codec/JsonValueCodec.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import reactor.core.publisher.Mono;
2020

2121
import java.io.InputStream;
22+
import java.io.Reader;
2223
import java.lang.reflect.Field;
2324
import java.lang.reflect.ParameterizedType;
2425
import java.lang.reflect.Type;
@@ -159,27 +160,29 @@ public Object decode(Object data) {
159160
try {
160161
Object target = data;
161162

162-
if (data instanceof Clob) {
163-
target = mapper.readValue(((Clob) data).getCharacterStream(), jacksonType);
164-
} else if (data instanceof Blob) {
165-
target = mapper.readValue(((Blob) data).getBinaryStream(), jacksonType);
163+
if (data instanceof Clob _clob) {
164+
target = mapper.readValue(_clob.getCharacterStream(), jacksonType);
165+
} else if (data instanceof Blob _blob) {
166+
target = mapper.readValue(_blob.getBinaryStream(), jacksonType);
166167
} else if (data instanceof InputStream) {
167168
target = mapper.readValue((InputStream) data, jacksonType);
168-
} else if (data instanceof byte[]) {
169-
target = mapper.readValue((byte[]) data, jacksonType);
170-
} else if (data instanceof String) {
171-
target = doRead(((String) data));
169+
} else if (data instanceof byte[] bytes) {
170+
target = mapper.readValue(bytes, jacksonType);
171+
} else if (data instanceof CharSequence) {
172+
target = doRead(String.valueOf(data));
173+
} else if (data instanceof Reader reader) {
174+
target = mapper.readValue(reader, jacksonType);
172175
} else if (data instanceof ByteBuffer) {
173176
return doRead(new ByteBufferBackedInputStream(((ByteBuffer) data)));
174177
} else if (FeatureUtils.r2dbcIsAlive()) {
175178
Mono<?> mono = null;
176-
if (data instanceof io.r2dbc.spi.Clob) {
177-
mono = Flux.from(((io.r2dbc.spi.Clob) data).stream())
179+
if (data instanceof io.r2dbc.spi.Clob _clob) {
180+
mono = Flux.from(_clob.stream())
178181
.collect(Collectors.joining())
179182
.map(this::doRead);
180183

181-
} else if (data instanceof io.r2dbc.spi.Blob) {
182-
mono = Mono.from(((io.r2dbc.spi.Blob) data).stream())
184+
} else if (data instanceof io.r2dbc.spi.Blob _blob) {
185+
mono = Mono.from(_blob.stream())
183186
.map(ByteBufferBackedInputStream::new)
184187
.map(this::doRead);
185188
}
@@ -204,6 +207,9 @@ public Object decode(Object data) {
204207
if (targetType == Flux.class) {
205208
return target == null ? Flux.empty() : Flux.just(target);
206209
}
210+
if (target == null) {
211+
return null;
212+
}
207213
log.warn("unsupported json format:{}", data);
208214
return target;
209215
} catch (Throwable e) {

0 commit comments

Comments
 (0)