简体   繁体   中英

Method info( java.util.HashMap ) not found in class'org.apache.log.Logger'

 log.info(m.differenceValue(jsonElement1,jsonElement2)); 

calling function from beanshell. The code implemented in jar file.

public static <K, V> Map<String,Object> differenceValue(JsonElement json1, JsonElement json2){
    Gson g = new Gson();

    Type mapType = new TypeToken<Map<String, Object>>(){}.getType();
    Map<String,Object> firstMap = g.fromJson(json1, mapType);
    Map<String, Object> secondMap = g.fromJson(json2, mapType);
   return(mapDifference(firstMap,secondMap));
}      
public static <K, V> Map<K, V> mapDifference(Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right) {
    Map<K, V> difference =  new HashMap<K, V>();
    difference.putAll(left);
    difference.putAll(right);
    difference.entrySet().removeAll(right.entrySet());
    return difference;
}

Is is working fine in eclipse but in jmeter it is throwing

error:Method info( java.util.HashMap ) not found in class'org.apache.log.Logger'

You are trying to pass a Map to Logger while it accepts only Strings for info() , warn() , etc. methods to you will need to cast the Map to String somehow.

Also I don't think you have generics support in Beanshell, consider switching to JSR223 Elements and Groovy language instead.

try log.info(m.differenceValue(jsonElement1,jsonElement2).toString());

according to documentation, that might work for HashMap (depending on what you have for the keys & values there)

public String toString()

Returns a string representation of this map. The string representation consists of a list of key-value mappings in the order returned by the map's entrySet view's iterator, enclosed in braces ("{}"). Adjacent mappings are separated by the characters ", " (comma and space). Each key-value mapping is rendered as the key followed by an equals sign ("=") followed by the associated value. Keys and values are converted to strings as by String.valueOf(Object).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM