修复bson问题

This commit is contained in:
redkale
2023-10-16 20:07:30 +08:00
parent c4b91ebbc6
commit 8c625e93c7
2 changed files with 26 additions and 30 deletions

View File

@@ -192,7 +192,7 @@ public class BsonConvert extends BinaryConvert<BsonReader, BsonWriter> {
//------------------------------ convertTo ----------------------------------------------------------- //------------------------------ convertTo -----------------------------------------------------------
@Override @Override
public byte[] convertTo(final Type type, final Object value) { public byte[] convertTo(final Type type, final Object value) {
if (value == null) { if (type == null && value == null) {
final BsonWriter out = pollWriter(); final BsonWriter out = pollWriter();
out.writeNull(); out.writeNull();
byte[] result = out.toArray(); byte[] result = out.toArray();
@@ -214,7 +214,7 @@ public class BsonConvert extends BinaryConvert<BsonReader, BsonWriter> {
@Override @Override
public void convertToBytes(final Type type, final Object value, final ConvertBytesHandler handler) { public void convertToBytes(final Type type, final Object value, final ConvertBytesHandler handler) {
final BsonWriter writer = pollWriter(); final BsonWriter writer = pollWriter();
if (type == null) { if (type == null && type == null) {
writer.writeNull(); writer.writeNull();
} else { } else {
factory.loadEncoder(type).convertTo(writer, value); factory.loadEncoder(type).convertTo(writer, value);
@@ -226,7 +226,7 @@ public class BsonConvert extends BinaryConvert<BsonReader, BsonWriter> {
public void convertToBytes(final ByteArray array, final Type type, final Object value) { public void convertToBytes(final ByteArray array, final Type type, final Object value) {
Objects.requireNonNull(array); Objects.requireNonNull(array);
final BsonWriter writer = configWrite(new BsonWriter(array).withFeatures(features)); final BsonWriter writer = configWrite(new BsonWriter(array).withFeatures(features));
if (value == null) { if (type == null && value == null) {
writer.writeNull(); writer.writeNull();
} else { } else {
factory.loadEncoder(type == null ? value.getClass() : type).convertTo(writer, value); factory.loadEncoder(type == null ? value.getClass() : type).convertTo(writer, value);
@@ -239,7 +239,7 @@ public class BsonConvert extends BinaryConvert<BsonReader, BsonWriter> {
} }
public void convertTo(final OutputStream out, final Type type, final Object value) { public void convertTo(final OutputStream out, final Type type, final Object value) {
if (value == null) { if (type == null && value == null) {
pollWriter(out).writeNull(); pollWriter(out).writeNull();
} else { } else {
factory.loadEncoder(type == null ? value.getClass() : type).convertTo(pollWriter(out), value); factory.loadEncoder(type == null ? value.getClass() : type).convertTo(pollWriter(out), value);
@@ -250,7 +250,7 @@ public class BsonConvert extends BinaryConvert<BsonReader, BsonWriter> {
public ByteBuffer[] convertTo(final Supplier<ByteBuffer> supplier, final Type type, final Object value) { public ByteBuffer[] convertTo(final Supplier<ByteBuffer> supplier, final Type type, final Object value) {
Objects.requireNonNull(supplier); Objects.requireNonNull(supplier);
BsonByteBufferWriter writer = pollWriter(supplier); BsonByteBufferWriter writer = pollWriter(supplier);
if (value == null) { if (type == null && value == null) {
writer.writeNull(); writer.writeNull();
} else { } else {
factory.loadEncoder(type == null ? value.getClass() : type).convertTo(writer, value); factory.loadEncoder(type == null ? value.getClass() : type).convertTo(writer, value);
@@ -260,7 +260,7 @@ public class BsonConvert extends BinaryConvert<BsonReader, BsonWriter> {
@Override @Override
public void convertTo(final BsonWriter writer, final Type type, final Object value) { public void convertTo(final BsonWriter writer, final Type type, final Object value) {
if (value == null) { if (type == null && value == null) { //必须判断type==null
writer.writeNull(); writer.writeNull();
} else { } else {
factory.loadEncoder(type == null ? value.getClass() : type).convertTo(writer, value); factory.loadEncoder(type == null ? value.getClass() : type).convertTo(writer, value);

View File

@@ -330,8 +330,7 @@ public abstract class Client<C extends ClientConnection<R, P>, R extends ClientR
if (authenticate != null) { if (authenticate != null) {
future = future.thenCompose(authenticate); future = future.thenCompose(authenticate);
} }
return future.thenCompose(c -> { return future.thenApply(c -> {
return CompletableFuture.supplyAsync(() -> {
c.setAuthenticated(true); c.setAuthenticated(true);
if (pool) { if (pool) {
this.connArray[connIndex] = c; this.connArray[connIndex] = c;
@@ -343,7 +342,6 @@ public abstract class Client<C extends ClientConnection<R, P>, R extends ClientR
} }
} }
return c; return c;
}, c.channel.getWriteIOThread());
}).whenComplete((r, t) -> { }).whenComplete((r, t) -> {
if (pool && t != null) { if (pool && t != null) {
this.connOpenStates[connIndex].set(false); this.connOpenStates[connIndex].set(false);
@@ -392,8 +390,7 @@ public abstract class Client<C extends ClientConnection<R, P>, R extends ClientR
if (authenticate != null) { if (authenticate != null) {
future = future.thenCompose(authenticate); future = future.thenCompose(authenticate);
} }
return future.thenCompose(c -> { return future.thenApply(c -> {
return CompletableFuture.supplyAsync(() -> {
c.setAuthenticated(true); c.setAuthenticated(true);
if (pool) { if (pool) {
entry.connection = c; entry.connection = c;
@@ -405,7 +402,6 @@ public abstract class Client<C extends ClientConnection<R, P>, R extends ClientR
} }
} }
return c; return c;
}, c.channel.getWriteIOThread());
}).whenComplete((r, t) -> { }).whenComplete((r, t) -> {
if (pool && t != null) { if (pool && t != null) {
entry.connOpenState.set(false); entry.connOpenState.set(false);