mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
7bdec92d8b
commit
0e75e75f5d
@ -201,6 +201,7 @@ public class JSONMapper implements Serializable {
|
|||||||
* <li>standard property (Double, String, et al) =》 原对象</li>
|
* <li>standard property (Double, String, et al) =》 原对象</li>
|
||||||
* <li>其它 =》 尝试包装为JSONObject,否则返回{@code null}</li>
|
* <li>其它 =》 尝试包装为JSONObject,否则返回{@code null}</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
|
* 注意,此方法不支持JSON字符串的解析,解析请用{@link #map(CharSequence)}
|
||||||
*
|
*
|
||||||
* @param obj 被映射的对象
|
* @param obj 被映射的对象
|
||||||
* @return 映射后的值,null表示此值需被忽略
|
* @return 映射后的值,null表示此值需被忽略
|
||||||
@ -249,11 +250,11 @@ public class JSONMapper implements Serializable {
|
|||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @param obj 被映射的对象
|
* @param obj 被映射的对象
|
||||||
* @param json 被映射的到的对象,{@code null}表示自动识别
|
* @param json 被映射的到的对象,{@code null}表示根据序列化器自动识别
|
||||||
* @param <T> JSON类型
|
* @param <T> JSON类型
|
||||||
* @return 映射后的值,null表示此值需被忽略
|
* @return 映射后的值,null表示此值需被忽略
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"ReassignedVariable", "unchecked"})
|
@SuppressWarnings({"unchecked"})
|
||||||
private <T extends JSON> T mapTo(Object obj, final T json) {
|
private <T extends JSON> T mapTo(Object obj, final T json) {
|
||||||
if (null == obj) {
|
if (null == obj) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -81,24 +81,6 @@ public class IterTypeAdapter implements MatcherJSONSerializer<Object>, MatcherJS
|
|||||||
return deserialize(json, collectionClass, elementType);
|
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<Object>, MatcherJS
|
|||||||
return result;
|
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转换为集合
|
* 将JSONObject转换为集合
|
||||||
*
|
*
|
||||||
@ -126,7 +126,7 @@ public class IterTypeAdapter implements MatcherJSONSerializer<Object>, MatcherJS
|
|||||||
* @param result 结果集合
|
* @param result 结果集合
|
||||||
* @param elementType 元素类型
|
* @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)->{
|
json.forEach((key, value)->{
|
||||||
result.add(null == value ? null : value.toBean(elementType));
|
result.add(null == value ? null : value.toBean(elementType));
|
||||||
});
|
});
|
||||||
@ -139,7 +139,7 @@ public class IterTypeAdapter implements MatcherJSONSerializer<Object>, MatcherJS
|
|||||||
* @param result 结果集合
|
* @param result 结果集合
|
||||||
* @param elementType 元素类型
|
* @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)->{
|
json.forEach((element)->{
|
||||||
result.add(null == element ? null : element.toBean(elementType));
|
result.add(null == element ? null : element.toBean(elementType));
|
||||||
});
|
});
|
||||||
|
@ -74,7 +74,7 @@ public class MapTypeAdapter implements MatcherJSONSerializer<Map<?, ?>>, Matcher
|
|||||||
} else{
|
} else{
|
||||||
iter = bean.entrySet().iterator();
|
iter = bean.entrySet().iterator();
|
||||||
}
|
}
|
||||||
IterTypeAdapter.INSTANCE.mapFromIterator(bean, iter, (JSONArray) contextJson);
|
IterTypeAdapter.mapFromIterator(bean, iter, (JSONArray) contextJson);
|
||||||
return contextJson;
|
return contextJson;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user