This commit is contained in:
Redkale
2017-12-19 16:40:58 +08:00
parent 709439bfca
commit 30b2cffcb8
2 changed files with 24 additions and 3 deletions

View File

@@ -160,7 +160,7 @@ public final class JsonConvert extends TextConvert<JsonReader, JsonWriter> {
if (value == null) {
new JsonStreamWriter(tiny, out).writeNull();
} else {
factory.loadEncoder(value.getClass()).convertTo(new JsonStreamWriter(tiny, out), value);
convertTo(out, value.getClass(), value);
}
}
@@ -169,7 +169,15 @@ public final class JsonConvert extends TextConvert<JsonReader, JsonWriter> {
if (value == null) {
new JsonStreamWriter(tiny, out).writeNull();
} else {
factory.loadEncoder(type).convertTo(new JsonStreamWriter(tiny, out), value);
final JsonWriter writer = writerPool.get().tiny(tiny);
factory.loadEncoder(type).convertTo(writer, value);
byte[] bs = writer.toBytes();
writerPool.accept(writer);
try {
out.write(bs);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
@@ -177,7 +185,15 @@ public final class JsonConvert extends TextConvert<JsonReader, JsonWriter> {
if (values == null) {
new JsonStreamWriter(tiny, out).writeNull();
} else {
((AnyEncoder) factory.getAnyEncoder()).convertMapTo(new JsonStreamWriter(tiny, out), values);
final JsonWriter writer = writerPool.get().tiny(tiny);
((AnyEncoder) factory.getAnyEncoder()).convertMapTo(writer, values);
byte[] bs = writer.toBytes();
writerPool.accept(writer);
try {
out.write(bs);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

View File

@@ -59,6 +59,7 @@ public class JsonWriter extends Writer {
* 返回指定至少指定长度的缓冲区
*
* @param len
*
* @return
*/
private char[] expand(int len) {
@@ -108,6 +109,10 @@ public class JsonWriter extends Writer {
return new ByteBuffer[]{ByteBuffer.wrap(Utility.encodeUTF8(content, 0, count))};
}
public byte[] toBytes() {
return Utility.encodeUTF8(content, 0, count);
}
public int count() {
return this.count;
}