添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
含蓄的汽水  ·  Element ...·  12 月前    · 
沉稳的草稿本  ·  解决CONFIG -= ...·  1 年前    · 
俊秀的小狗  ·  ignoreDependencyInterf ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Error invoking bsh method: eval Sourced file: inline evaluation of: `import org.skyscreamer.jsonassert.Customization; Constructor error: Can't find

Ask Question

I use jmeter to comapre json data.use org.skyscreamer.jsonassert. suceess in idea with jdk8, but failed in jmeter this is error info.

i have imported jsonassert-1.5.1.jar and android-json-0.0.20131108.vaadin1.jar into %Jmeter%lib,jackson use 2.13.3 version.jmeter version is 5.5 .

Response code:500
Response message:org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval   Sourced file: inline evaluation of: ``import org.skyscreamer.jsonassert.Customization; import org.skyscreamer.jsonasse . . . '' : Constructor error: Can't find constructor: org.skyscreamer.jsonassert.comparator.CustomComparator( org.skyscreamer.jsonassert.JSONCompareMode, org.skyscreamer.jsonassert.Customization ) in class: org.skyscreamer.jsonassert.comparator.CustomComparator

this is beanshell sampler ,the code i write in the jmeter

import org.skyscreamer.jsonassert.Customization;
import org.skyscreamer.jsonassert.JSONCompare;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.skyscreamer.jsonassert.JSONCompareResult;
import org.skyscreamer.jsonassert.ValueMatcher;
import org.skyscreamer.jsonassert.comparator.CustomComparator;
import org.json.JSONException;
String newResponseMessage = vars.get("new_S{custNo}");
String oldResponseMessage = vars.get("old_S{custNo}");
log.info("oldRes"+oldResponseMessage);
log.info("newRes"+newResponseMessage);
ValueMatcher matcher = new ValueMatcher() {
            public boolean equal(Object o1, Object o2) {
                return true;
Customization customization = new Customization("orgSeqNo", matcher);
JSONCompareResult result;
try {
    result = JSONCompare.compareJSON(newResponseMessage, oldResponseMessage, new CustomComparator(JSONCompareMode.NON_EXTENSIBLE,customization));
    if (result.passed()) {
        System.out.println("no different");
    } else {
        System.out.println(result.getMessage());
        log.error(result.getMessage());
    //    ctx.getEngine().stopTest();
}catch (JSONException e){
    log.error("Beanshell failure: ", e);
    throw ex;

code in jmeter beanshell sampler

error info picture

i have imported jsonassert-1.5.1.jar and android-json-0.0.20131108.vaadin1.jar into %Jmeter%lib and %Jmeter%/lib/ext both,jackson use 2.13.3 version.jmeter version is 5.5 . enter image description here

I use jmeter to comapre json data.use org.skyscreamer.jsonassert. suceess in idea with jdk8, but failed in jmeter these are codes i write with jdk8,success run,but failed in jmeter

<dependency>
    <groupId>org.skyscreamer</groupId>
    <artifactId>jsonassert</artifactId>
    <version>1.5.1</version>
</dependency>
public class Main {
    static String jsonStr1 = "{\"orgSeqNo\":\"123123\",\"code\":200,\"person\":{\"partyId\":\"10000000001\",\"partyName\":\"john\",\"partyCertType\":\"10100\",\"partyCertNo\":\"320925199612122314\",\"partyStatus\":\"1\",\"addresses\":[{\"addrId\":\"1\",\"partyId\":\"10000000001\",\"city\":\"suchou\",\"detailAddr\":\"asdfghqwe\",\"addrType\":103,\"phone\":\"13213137625\"},{\"addrId\":\"2\",\"partyId\":\"10000000001\",\"city\":\"suchou\",\"detailAddr\":\"asdfghqwe\",\"addrType\":\"101\",\"phone\":\"13213137625\"},{\"addrId\":\"3\",\"partyId\":\"10000000001\",\"city\":\"suchou\",\"detailAddr\":\"asdfghqwe\",\"addrType\":\"102\",\"phone\":\"13213137625\"}]},\"message\":\"ok\"}";
    static String jsonStr2 = "{\"orgSeqNo\":\"12e9fc45c09b4a69b7aa2bbcb1313cba\",\"code\":200,\"person\":{\"partyId\":\"10000000001\",\"partyName\":\"john\",\"partyCertType\":\"10100\",\"partyCertNo\":\"320925199612122314\",\"partyStatus\":\"1\",\"addresses\":[{\"addrId\":\"1\",\"partyId\":\"10000000001\",\"city\":\"suchou\",\"detailAddr\":\"asdfghqwe\",\"addrType\":\"103\",\"phone\":\"13213137625\"},{\"addrId\":\"2\",\"partyId\":\"10000000001\",\"city\":\"suchou\",\"detailAddr\":\"asdfghqwe\",\"addrType\":\"101\",\"phone\":\"13213137625\"},{\"addrId\":\"3\",\"partyId\":\"10000000001\",\"city\":\"suchou\",\"detailAddr\":\"asdfghqwe\",\"addrType\":\"102\",\"phone\":\"13213137625\"}]},\"message\":\"ok\"}";
    static String jsonStr3 = "{\"orgSeqNo\":\"12e9fc45c09b4a69b7aa2bbcb1313cba\",\"code\":200,\"person\":{\"partyId\":\"10000000001\",\"partyName\":\"john\",\"partyCertType\":\"10100\",\"partyCertNo\":\"320925199612122314\",\"partyStatus\":\"1\",\"addresses\":[{\"addrId\":\"2\",\"partyId\":\"10000000001\",\"city\":\"suchou\",\"detailAddr\":\"asdfghqwe\",\"addrType\":\"101\",\"phone\":\"13213137625\"},{\"addrId\":\"1\",\"partyId\":\"10000000001\",\"city\":\"suchou\",\"detailAddr\":\"asdfghqwe\",\"addrType\":\"103\",\"phone\":\"13213137625\"},{\"addrId\":\"3\",\"partyId\":\"10000000001\",\"city\":\"suchou\",\"detailAddr\":\"asdfghqwe\",\"addrType\":\"102\",\"phone\":\"13213137625\"}]},\"message\":\"ok\"}";
    static String jsonStr4 = "{\"orgSeqNo\":\"12e9fc45c09b4a69b7aa2bbcb1313cba\",\"code\":200,\"person\":{\"partyId\":\"10000000001\",\"partyName\":\"john\",\"partyCertType\":\"10100\",\"partyCertNo\":\"320925199612122314\",\"partyStatus\":\"1\",\"addresses\":[{\"addrId\":\"1\",\"partyId\":\"10000000001\",\"city\":\"suchou\",\"detailAddr\":\"asdfghqwe\",\"addrType\":103,\"phone\":\"13213137625\"},{\"addrId\":\"2\",\"partyId\":\"10000000001\",\"city\":\"suchou\",\"detailAddr\":\"asdfghqwe\",\"addrType\":\"101\",\"phone\":\"13213137625\"},{\"addrId\":\"3\",\"partyId\":\"10000000001\",\"city\":\"suchou\",\"detailAddr\":\"asdfghqwe\",\"addrType\":\"102\",\"phone\":\"13213137625\"}]},\"message\":\"ok\"}";
    public static void main(String[] args) {
//        Customization customization = new Customization("orgSeqNo", (o1, o2) -> true);
        ValueMatcher matcher = new ValueMatcher() {
            @Override
            public boolean equal(Object o1, Object o2) {
                return true;
        Customization customization = new Customization("orgSeqNo", matcher);
        JSONCompareResult result = null;
        try {
            result  = JSONCompare.compareJSON(jsonStr1, jsonStr3, new CustomComparator(JSONCompareMode.NON_EXTENSIBLE,customization));
            if (result1.passed()) {
                System.out.println("no different");
            } else {
                System.out.println(result.getMessage());
        } catch (JSONException e) {
            e.printStackTrace();
            throw new RuntimeException(e);

next is result,i want jmeter also like this result

person.addresses[addrId=1].addrType
Expected: 103
     got: 103

Program execution result picture

i have imported jsonassert-1.5.1.jar and android-json-0.0.20131108.vaadin1.jar into %Jmeter%lib,jackson use 2.13.3 version.jmeter version is 5.5 .

run success in jvm , but error info in jmeter...

Beanshell != Java so even given your code "suceess in idea with jdk8" it doesn't necessarily mean that it will "suceess" in JMeter's Beanshell components.

Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting so my expectation is that if you switch to the JSR223 Sampler and use groovy your code will "suceess" as well.

More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.