diff --git a/hutool-json/src/main/java/org/dromara/hutool/json/serializer/JSONMapper.java b/hutool-json/src/main/java/org/dromara/hutool/json/serializer/JSONMapper.java index 4e15b4d47..68b727d02 100644 --- a/hutool-json/src/main/java/org/dromara/hutool/json/serializer/JSONMapper.java +++ b/hutool-json/src/main/java/org/dromara/hutool/json/serializer/JSONMapper.java @@ -201,6 +201,7 @@ public class JSONMapper implements Serializable { *
  • standard property (Double, String, et al) =》 原对象
  • *
  • 其它 =》 尝试包装为JSONObject,否则返回{@code null}
  • * + * 注意,此方法不支持JSON字符串的解析,解析请用{@link #map(CharSequence)} * * @param obj 被映射的对象 * @return 映射后的值,null表示此值需被忽略 @@ -249,11 +250,11 @@ public class JSONMapper implements Serializable { * * * @param obj 被映射的对象 - * @param json 被映射的到的对象,{@code null}表示自动识别 + * @param json 被映射的到的对象,{@code null}表示根据序列化器自动识别 * @param JSON类型 * @return 映射后的值,null表示此值需被忽略 */ - @SuppressWarnings({"ReassignedVariable", "unchecked"}) + @SuppressWarnings({"unchecked"}) private T mapTo(Object obj, final T json) { if (null == obj) { return null; diff --git a/hutool-json/src/main/java/org/dromara/hutool/json/serializer/impl/IterTypeAdapter.java b/hutool-json/src/main/java/org/dromara/hutool/json/serializer/impl/IterTypeAdapter.java index a919e27ba..06a50e48b 100644 --- a/hutool-json/src/main/java/org/dromara/hutool/json/serializer/impl/IterTypeAdapter.java +++ b/hutool-json/src/main/java/org/dromara/hutool/json/serializer/impl/IterTypeAdapter.java @@ -81,24 +81,6 @@ public class IterTypeAdapter implements MatcherJSONSerializer, MatcherJS return deserialize(json, collectionClass, elementType); } - /** - * 从Iterator中读取数据,并添加到JSONArray中 - * - * @param source 源对象,用于检查循环引用 - * @param iter {@link Iterator} - * @param jsonArray {@link JSONArray} - */ - public void mapFromIterator(final Object source, final Iterator iter, final JSONArray jsonArray) { - Object next; - while (iter.hasNext()) { - next = iter.next(); - // 检查循环引用 - if (next != source) { - jsonArray.addObj(next); - } - } - } - /** * 反序列化 * @@ -119,6 +101,24 @@ public class IterTypeAdapter implements MatcherJSONSerializer, MatcherJS return result; } + /** + * 从Iterator中读取数据,并添加到JSONArray中 + * + * @param source 源对象,用于检查循环引用 + * @param iter {@link Iterator} + * @param jsonArray {@link JSONArray} + */ + static void mapFromIterator(final Object source, final Iterator iter, final JSONArray jsonArray) { + Object next; + while (iter.hasNext()) { + next = iter.next(); + // 检查循环引用 + if (next != source) { + jsonArray.addObj(next); + } + } + } + /** * 将JSONObject转换为集合 * @@ -126,7 +126,7 @@ public class IterTypeAdapter implements MatcherJSONSerializer, MatcherJS * @param result 结果集合 * @param elementType 元素类型 */ - private void fill(final JSONObject json, final Collection result, final Type elementType) { + private static void fill(final JSONObject json, final Collection result, final Type elementType) { json.forEach((key, value)->{ result.add(null == value ? null : value.toBean(elementType)); }); @@ -139,7 +139,7 @@ public class IterTypeAdapter implements MatcherJSONSerializer, MatcherJS * @param result 结果集合 * @param elementType 元素类型 */ - private void fill(final JSONArray json, final Collection result, final Type elementType) { + private static void fill(final JSONArray json, final Collection result, final Type elementType) { json.forEach((element)->{ result.add(null == element ? null : element.toBean(elementType)); }); diff --git a/hutool-json/src/main/java/org/dromara/hutool/json/serializer/impl/MapTypeAdapter.java b/hutool-json/src/main/java/org/dromara/hutool/json/serializer/impl/MapTypeAdapter.java index f5401f9d5..153e3078a 100644 --- a/hutool-json/src/main/java/org/dromara/hutool/json/serializer/impl/MapTypeAdapter.java +++ b/hutool-json/src/main/java/org/dromara/hutool/json/serializer/impl/MapTypeAdapter.java @@ -74,7 +74,7 @@ public class MapTypeAdapter implements MatcherJSONSerializer>, Matcher } else{ iter = bean.entrySet().iterator(); } - IterTypeAdapter.INSTANCE.mapFromIterator(bean, iter, (JSONArray) contextJson); + IterTypeAdapter.mapFromIterator(bean, iter, (JSONArray) contextJson); return contextJson; }