Closed 0019 closed 1 year ago
Well, if I specify the data in a map then it works:
Map d = new HashMap<String, Integer>(){{ put("x", 0); put("y", 1); }};
Does it only take in map? What if my data is nested?
I'm having exactly the same problem. The library doesn't seem to support nested objects. Any plans to enhance it ?
It does support nested objects.
Map<String, String> nested = Collections.singletonMap("B", "C");
Map<String, Object> data = Collections.singletonMap("A", nested);
As JSON this is {"A": {"B": "C"}}
.
If you have a JSON string as your data, try converting to an Object
using gson.fromJson
.
It does support nested objects.
Map<String, String> nested = Collections.singletonMap("B", "C"); Map<String, Object> data = Collections.singletonMap("A", nested);
As JSON this is
{"A": {"B": "C"}}
.If you have a JSON string as your data, try converting to an
Object
usinggson.fromJson
.
If I manually create map inside another map it works fine but I'm having issue passing any Object.
I tried example from the doc:
val expression = "{\"*\": [{\"var\": \"y.nested\"}, 2]}"
val data = Map("y" -> Map("nested" -> 555).asJava).asJava
// Evaluate the result.
val result = jsonLogic.apply(expression, data).asInstanceOf[Double]
println(result)
Prints: 1110.0
This one works fine but when I parse using gson / directly pass Object it doesn't seem to properly read the data
val expression = "{\"*\": [{\"var\": \"y.nested\"}, 2]}"
val data = Map("y" -> new JavaNested(6)).asJava
// Evaluate the result.
val result = jsonLogic.apply(expression, data).asInstanceOf[Double]
println(result)
Prints: 0.0
Am I missing something ?
`import io.github.jamsesso.jsonlogic.JsonLogic; import io.github.jamsesso.jsonlogic.JsonLogicException;
public class RuleEngine {
} `
What did I miss? It's driving me crazy...