Search code examples
javaapachejmeterbeanshell

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'


Solution

  • 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).