From b79a72c3658c71e25453090c068eb02d44ece87a Mon Sep 17 00:00:00 2001 From: feilong Date: Mon, 13 Nov 2023 19:55:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=20com.feilong.json.JsonToJav?= =?UTF-8?q?aConfig.classMap=20javadoc=20fix=20#617?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/feilong/json/JsonToJavaConfig.java | 184 +++++++++++++++++- 1 file changed, 180 insertions(+), 4 deletions(-) diff --git a/feilong-json/src/main/java/com/feilong/json/JsonToJavaConfig.java b/feilong-json/src/main/java/com/feilong/json/JsonToJavaConfig.java index 9f2e8e60c..f3e8eb8bb 100755 --- a/feilong-json/src/main/java/com/feilong/json/JsonToJavaConfig.java +++ b/feilong-json/src/main/java/com/feilong/json/JsonToJavaConfig.java @@ -41,7 +41,50 @@ public class JsonToJavaConfig extends AbstractConfig{ //--------------------------------------------------------------- /** - * The class map. + * 用来设置复杂自定义对象转换. + * + *

示例:

+ * + *
+ * 有以下两个bean + * + *
+     * 
+     * public class MyBean{
+     * 
+     *     private Long id;
+     * 
+     *     private Person person;
+     * 
+     *     //setter/getter省略
+     * 
+     * }
+     * 
+     * public class Person{
+     * 
+     *     private String name;
+     * 
+     *     private Date dateAttr;
+     * 
+     *     //setter/getter省略
+     * }
+     * 
+     * 现在需要把这段json 转成MyBean
+     * 
+     * String json = "{'mybean':{'data':[{'name':'get'}]}}";
+     * 
+     * 代码写法如下:
+     * 
+     * Map{@code >} classMap = newHashMap();
+     * classMap.put("data", Person.class);
+     * 
+     * JsonToJavaConfig jsonToJavaConfig = new JsonToJavaConfig(MyBean.class);
+     * jsonToJavaConfig.setClassMap(classMap);
+     * 
+     * MyBean myBean = JsonUtil.toBean(json, jsonToJavaConfig);
+     * 
+ * + *
* * @see com.feilong.lib.json.JsonConfig#setClassMap(Map) */ @@ -252,7 +295,50 @@ public JsonToJavaConfig(Class rootClass, JavaIdentifierTransformer javaIdenti * @param rootClass * the root class * @param classMap - * the class map + * 用来设置复杂自定义对象转换. + * + *

示例:

+ * + *
+ * 有以下两个bean + * + *
+     * 
+     * public class MyBean{
+     * 
+     *     private Long id;
+     * 
+     *     private Person person;
+     * 
+     *     //setter/getter省略
+     * 
+     * }
+     * 
+     * public class Person{
+     * 
+     *     private String name;
+     * 
+     *     private Date dateAttr;
+     * 
+     *     //setter/getter省略
+     * }
+     * 
+     * 现在需要把这段json 转成MyBean
+     * 
+     * String json = "{'mybean':{'data':[{'name':'get'}]}}";
+     * 
+     * 代码写法如下:
+     * 
+     * Map{@code >} classMap = newHashMap();
+     * classMap.put("data", Person.class);
+     * 
+     * JsonToJavaConfig jsonToJavaConfig = new JsonToJavaConfig(MyBean.class);
+     * jsonToJavaConfig.setClassMap(classMap);
+     * 
+     * MyBean myBean = JsonUtil.toBean(json, jsonToJavaConfig);
+     *            
+ * + *
*/ public JsonToJavaConfig(Class rootClass, Map> classMap){ super(); @@ -461,7 +547,52 @@ public void setRootClass(Class rootClass){ } /** - * Gets the class map. + * 用来设置复杂自定义对象转换. + * + *

示例:

+ * + *
+ * 有以下两个bean + * + *
+     * 
+     * public class MyBean{
+     * 
+     *     private Long id;
+     * 
+     *     private Person person;
+     * 
+     *     //setter/getter省略
+     * 
+     * }
+     * 
+     * public class Person{
+     * 
+     *     private String name;
+     * 
+     *     private Date dateAttr;
+     * 
+     *     //setter/getter省略
+     * }
+     * 
+     * 现在需要把这段json 转成MyBean
+     * 
+     * String json = "{'mybean':{'data':[{'name':'get'}]}}";
+     * 
+     * 代码写法如下:
+     * 
+     * Map{@code >} classMap = newHashMap();
+     * classMap.put("data", Person.class);
+     * 
+     * JsonToJavaConfig jsonToJavaConfig = new JsonToJavaConfig(MyBean.class);
+     * jsonToJavaConfig.setClassMap(classMap);
+     * 
+     * MyBean myBean = JsonUtil.toBean(json, jsonToJavaConfig);
+     * 
+ * + *
+ * + * @see com.feilong.lib.json.JsonConfig#setClassMap(Map) * * @return the classMap */ @@ -470,7 +601,52 @@ public Map> getClassMap(){ } /** - * 设置 class map. + * 用来设置复杂自定义对象转换. + * + *

示例:

+ * + *
+ * 有以下两个bean + * + *
+     * 
+     * public class MyBean{
+     * 
+     *     private Long id;
+     * 
+     *     private Person person;
+     * 
+     *     //setter/getter省略
+     * 
+     * }
+     * 
+     * public class Person{
+     * 
+     *     private String name;
+     * 
+     *     private Date dateAttr;
+     * 
+     *     //setter/getter省略
+     * }
+     * 
+     * 现在需要把这段json 转成MyBean
+     * 
+     * String json = "{'mybean':{'data':[{'name':'get'}]}}";
+     * 
+     * 代码写法如下:
+     * 
+     * Map{@code >} classMap = newHashMap();
+     * classMap.put("data", Person.class);
+     * 
+     * JsonToJavaConfig jsonToJavaConfig = new JsonToJavaConfig(MyBean.class);
+     * jsonToJavaConfig.setClassMap(classMap);
+     * 
+     * MyBean myBean = JsonUtil.toBean(json, jsonToJavaConfig);
+     * 
+ * + *
+ * + * @see com.feilong.lib.json.JsonConfig#setClassMap(Map) * * @param classMap * the classMap to set