fix bug#I3AXIJ

This commit is contained in:
Looly
2021-03-11 17:10:02 +08:00
parent 5cdbd16c0b
commit 511f688d1e
4 changed files with 65 additions and 26 deletions

View File

@@ -546,6 +546,35 @@ public class JSONUtil {
return (null == json || StrUtil.isBlank(expression)) ? null : json.getByPath(expression);
}
/**
* 通过表达式获取JSON中嵌套的对象<br>
* <ol>
* <li>.表达式可以获取Bean对象中的属性字段值或者Map中key对应的值</li>
* <li>[]表达式可以获取集合等对象中对应index的值</li>
* </ol>
* <p>
* 表达式栗子:
*
* <pre>
* persion
* persion.name
* persons[3]
* person.friends[5].name
* </pre>
*
* @param <T> 值类型
* @param json {@link JSON}
* @param expression 表达式
* @param defaultValue 默认值
* @return 对象
* @see JSON#getByPath(String)
* @since 5.6.0
*/
@SuppressWarnings("unchecked")
public static <T> T getByPath(JSON json, String expression, T defaultValue) {
return (T) ObjectUtil.defaultIfNull(getByPath(json, expression), defaultValue);
}
/**
* 设置表达式指定位置或filed对应的值<br>
* 若表达式指向一个JSONArray则设置其坐标对应位置的值若指向JSONObject则put对应key的值<br>