spark85 / json-path

Automatically exported from code.google.com/p/json-path
0 stars 0 forks source link

ExpressionEvaluator.eval() should accept additional value types #41

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a class with an Object field.
2. Create an instance of the class with the field set to new Double(8.95)
3. call ExpressionEvaluator.eval() with your object, "<", "10"

public class WrappedJsonValue {
    Object value;

    public WrappedJsonValue(Object value) {
        this.value = value;
    }

    public Object getValue() {
        return value;
    }

    public static void main(String[] args) {
        boolean result = ExpressionEvaluator.eval(new WrappedValue(new Double(8.95)), "<", "10");
        System.out.println(result);
    }
}

What is the expected output? What do you see instead?
I would like it to evaluate the Double and return true. Instead, it returns 
false because it can't handle a WrappedJsonValue object.

What version of the product are you using? On what operating system?
0.9.2-SNAPSHOT, windows

Please provide any additional information below.

My use case must maintain metadata associated with JSON values - offsets in the 
source document. To accomplish this, I created the following:
1. a JsonProvider to wrap/unwrap values/arrays/maps as necessary
2. an extension of JSONParserString to override readArray, readObject, and 
readMain to get offsets and return one of the classes described below.
3. an extension of JSONArray, adding an Offset field
4. an extension of JSONObject, adding an Offset field
5. a wrapper class with an Offset field and an Object - to be used where a 
String, Boolean, or Number would otherwise be used

This covered all of my needs except evaluating expressions such as 
$.store.book[?(@.price > 10)]. The ExpressionEvaluator class assumes it will 
receive a String, Boolean, or Number.

I submitted a pull request with a very simplistic, but general solution.

Original issue reported on code.google.com by bucha...@uwalumni.com on 12 Nov 2013 at 10:27

GoogleCodeExporter commented 9 years ago
Implementation has be changed

Original comment by kalle.st...@gmail.com on 18 Sep 2014 at 5:40