diff --git a/convert.html b/convert.html index c593b11d0..de5840b5a 100644 --- a/convert.html +++ b/convert.html @@ -56,7 +56,7 @@ public <T> T convertFrom(final Type type, final char[] text, int start, int len); public <T> T convertFrom(final Type type, final ByteBuffer... buffers); -
范例:
+基本用法:
public class UserRecord {
private int userid;
@@ -101,7 +101,7 @@
System.out.println(childConvert.convertTo(user2)); //应该也是 {"userid":100,"username":"redkalename"}
}JsonConvert 支持非空构造函数:
+JsonConvert 支持非空构造函数, 必须在其构造函数加上 @ConstructorProperties 注释,且构造函数必须是public修饰。
public class UserRecord {
private int userid;
@@ -130,6 +130,28 @@
}
}JsonConvert 支持自定义Coder。
+public class FileSimpleCoder<R extends Reader, W extends Writer> extends SimpledCoder<R, W, File> {
+
+ public static final FileSimpleCoder instance = new FileSimpleCoder();
+
+ private static final org.redkale.convert.ext.StringSimpledCoder stringCoder = org.redkale.convert.ext.StringSimpledCoder.instance;
+
+ @Override
+ public void convertTo(W out, File value) {
+ stringCoder.convertTo(out, value == null ? null : value.getPath());
+ }
+
+ @Override
+ public File convertFrom(R in) {
+ String path = stringCoder.convertFrom(in);
+ return path == null ? null : new File(path);
+ }
+
+}
+
+JsonFactory.root().register(java.io.File.class, FileSimpleCoder.instance);
+