2121import java .util .*;
2222
2323import static apijson .orm .AbstractSQLConfig .PATTERN_SCHEMA ;
24+ import static apijson .orm .SQLConfig .TYPE_ITEM ;
2425
2526/**可远程调用的函数类
2627 * @author Lemon
@@ -156,28 +157,39 @@ public AbstractFunctionParser setCurrentObject(@NotNull JSONObject currentObject
156157 return this ;
157158 }
158159
159- /**根据路径从当前对象取值
160+ /**根据路径取值
160161 * @param path
161162 * @return
162163 * @param <T>
163164 */
164165 public <T extends Object > T getArgVal (String path ) {
165- return getArgVal (path , true ); // 误判概率很小 false);
166+ return getArgVal (path , null ); // 误判概率很小 false);
167+ }
168+ /**根据路径取值
169+ * @param path
170+ * @param clazz
171+ * @return
172+ * @param <T>
173+ */
174+ public <T extends Object > T getArgVal (String path , Class <T > clazz ) {
175+ return getArgVal (path , clazz , true );
166176 }
167177 /**根据路径取值
168178 * @param path
179+ * @param clazz
169180 * @param tryAll false-仅当前对象,true-本次请求的全局对象以及 Parser 缓存值
170181 * @return
171182 * @param <T>
172183 */
173- public <T extends Object > T getArgVal (String path , boolean tryAll ) {
174- T val = getArgVal (getCurrentObject (), path );
184+ public <T extends Object > T getArgVal (String path , Class < T > clazz , boolean tryAll ) {
185+ T val = getArgVal (getCurrentObject (), path , clazz );
175186 if (tryAll == false || val != null ) {
176187 return val ;
177188 }
178189
179190 Parser <?> p = getParser ();
180- return p == null ? null : (T ) p .getValueByPath (path );
191+ String targetPath = AbstractParser .getValuePath (getParentPath (), path );
192+ return p == null ? null : (T ) p .getValueByPath (targetPath );
181193 }
182194 /**根据路径从对象 obj 中取值
183195 * @param obj
@@ -186,7 +198,11 @@ public <T extends Object> T getArgVal(String path, boolean tryAll) {
186198 * @param <T>
187199 */
188200 public static <T extends Object > T getArgVal (JSONObject obj , String path ) {
189- return AbstractParser .getValue (obj , StringUtil .splitPath (path ));
201+ return getArgVal (obj , path , null );
202+ }
203+ public static <T extends Object > T getArgVal (JSONObject obj , String path , Class <T > clazz ) {
204+ Object v = AbstractParser .getValue (obj , StringUtil .splitPath (path ));
205+ return clazz == null ? (T ) v : TypeUtils .cast (v , clazz , ParserConfig .getGlobalInstance ());
190206 }
191207
192208
0 commit comments