This commit is contained in:
@@ -30,6 +30,14 @@ public final class JsonConvert extends Convert<JsonReader, JsonWriter> {
|
|||||||
this.tiny = tiny;
|
this.tiny = tiny;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JsonWriter pollJsonWriter() {
|
||||||
|
return writerPool.poll().setTiny(tiny);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void offerJsonWriter(JsonWriter out) {
|
||||||
|
if (out != null) writerPool.offer(out);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JsonFactory getFactory() {
|
public JsonFactory getFactory() {
|
||||||
return (JsonFactory) factory;
|
return (JsonFactory) factory;
|
||||||
@@ -57,8 +65,7 @@ public final class JsonConvert extends Convert<JsonReader, JsonWriter> {
|
|||||||
public String convertTo(final Type type, Object value) {
|
public String convertTo(final Type type, Object value) {
|
||||||
if (type == null) return null;
|
if (type == null) return null;
|
||||||
if (value == null) return "null";
|
if (value == null) return "null";
|
||||||
final JsonWriter out = writerPool.poll();
|
final JsonWriter out = writerPool.poll().setTiny(tiny);
|
||||||
out.setTiny(tiny);
|
|
||||||
factory.loadEncoder(type).convertTo(out, value);
|
factory.loadEncoder(type).convertTo(out, value);
|
||||||
String result = out.toString();
|
String result = out.toString();
|
||||||
writerPool.offer(out);
|
writerPool.offer(out);
|
||||||
@@ -70,6 +77,23 @@ public final class JsonConvert extends Convert<JsonReader, JsonWriter> {
|
|||||||
return convertTo(value.getClass(), value);
|
return convertTo(value.getClass(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void convertTo(final JsonWriter out, final Type type, Object value) {
|
||||||
|
if (type == null) return;
|
||||||
|
if (value == null) {
|
||||||
|
out.writeNull();
|
||||||
|
} else {
|
||||||
|
factory.loadEncoder(type).convertTo(out, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void convertTo(final JsonWriter out, Object value) {
|
||||||
|
if (value == null) {
|
||||||
|
out.writeNull();
|
||||||
|
} else {
|
||||||
|
factory.loadEncoder(value.getClass()).convertTo(out, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public byte[] convertToUTF8Bytes(Object value) {
|
public byte[] convertToUTF8Bytes(Object value) {
|
||||||
if (value == null) return new byte[]{110, 117, 108, 108};
|
if (value == null) return new byte[]{110, 117, 108, 108};
|
||||||
return convertToUTF8Bytes(value.getClass(), value);
|
return convertToUTF8Bytes(value.getClass(), value);
|
||||||
@@ -78,8 +102,7 @@ public final class JsonConvert extends Convert<JsonReader, JsonWriter> {
|
|||||||
public byte[] convertToUTF8Bytes(final Type type, Object value) {
|
public byte[] convertToUTF8Bytes(final Type type, Object value) {
|
||||||
if (type == null) return null;
|
if (type == null) return null;
|
||||||
if (value == null) return new byte[]{110, 117, 108, 108};
|
if (value == null) return new byte[]{110, 117, 108, 108};
|
||||||
final JsonWriter out = writerPool.poll();
|
final JsonWriter out = writerPool.poll().setTiny(tiny);
|
||||||
out.setTiny(tiny);
|
|
||||||
factory.loadEncoder(type).convertTo(out, value);
|
factory.loadEncoder(type).convertTo(out, value);
|
||||||
byte[] result = out.toUTF8Bytes();
|
byte[] result = out.toUTF8Bytes();
|
||||||
writerPool.offer(out);
|
writerPool.offer(out);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import com.wentch.redkale.util.*;
|
|||||||
*
|
*
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
public final class JsonWriter implements Writer {
|
public class JsonWriter implements Writer {
|
||||||
|
|
||||||
private static final char[] CHARS_TUREVALUE = "true".toCharArray();
|
private static final char[] CHARS_TUREVALUE = "true".toCharArray();
|
||||||
|
|
||||||
@@ -45,13 +45,13 @@ public final class JsonWriter implements Writer {
|
|||||||
return tiny;
|
return tiny;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTiny(boolean tiny) {
|
public JsonWriter setTiny(boolean tiny) {
|
||||||
this.tiny = tiny;
|
this.tiny = tiny;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回指定至少指定长度的缓冲区
|
* 返回指定至少指定长度的缓冲区
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user