Jmeter BeanShell调用可变长度参数(String...)的方法,报“method xxx not found in class ‘xxx‘”

问题

Bean Shell脚本:

vars.put("udx_flinksql_data",JSON.toJSONString(udx_flinksql_data, SerializerFeature.DisableCircularReferenceDetect));
}

错误信息:

2020-08-17 15:20:43,936 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval	Sourced file: inline evaluation of: ``import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONArray; i . . . '' : Error in method invocation: Static method toJSONString( com.alibaba.fastjson.JSONObject, com.alibaba.fastjson.serializer.SerializerFeature ) not found in class'com.alibaba.fastjson.JSON'
2020-08-17 15:20:43,936 WARN o.a.j.e.BeanShellPostProcessor: Problem in BeanShell script: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval	Sourced file: inline evaluation of: ``import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONArray; i . . . '' : Error in method invocation: Static method toJSONString( com.alibaba.fastjson.JSONObject, com.alibaba.fastjson.serializer.SerializerFeature ) not found in class'com.alibaba.fastjson.JSON'
2020-08-17 15:20:43,984 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval	Sourced file: inline evaluation of: ``import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSON;  //获取j . . . '' : Typed variable declaration
2020-08-17 15:20:43,984 WARN o.a.j.a.BeanShellAssertion: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval	Sourced file: inline evaluation of: ``import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSON;  //获取j . . . '' : Typed variable declaration

从报错日志看,是
toJSONString( com.alibaba.fastjson.JSONObject, com.alibaba.fastjson.serializer.SerializerFeature ) 这个方法在JSON类中找不到。
原因:fastjson中JSON类中toJSONString方法的features参数为可变长度参数列表
fastjson源码:

public static String toJSONString(Object object, SerializerFeature... features) {
	return toJSONString(object, DEFAULT_GENERATE_FEATURE, features);
}

解决方案

修改脚本,传入定长数组

SerializerFeature[] features = new SerializerFeature[1];
features[0]=SerializerFeature.DisableCircularReferenceDetect;
vars.put("udx_flinksql_data",JSON.toJSONString(udx_flinksql_data, features));

运行成功

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值