Closed pn closed 5 years ago
Does it work on json-logic.com in the playground?
On Fri, May 17, 2019 at 10:08 AM Paweł Nadolski notifications@github.com wrote:
I'm trying to use inoperator with arrays. It works with inline data but I'm not able to make it work with data object.
assertEquals(true, jsonLogic.apply("""{"in": [1, [1, 2, 3]]}""", null)) // this works
val data1 = mapOf("value" to 1) assertEquals(true, jsonLogic.apply("""{"in": [{"var": "value"}, [1, 2, 3]]}""", data1)) // does not work val data2 = mapOf("list" to listOf(1, 2, 3)) assertEquals(true, jsonLogic.apply("""{"in": [1, {"var": "list"}]}""", data2)) // does not work
Am I doing something wrong? Or is it a bug?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jamsesso/json-logic-java/issues/6?email_source=notifications&email_token=AAA2KIX5FBMOP3RNJGIYIIDPV2U4FA5CNFSM4HNVEA22YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GUMZC6A, or mute the thread https://github.com/notifications/unsubscribe-auth/AAA2KITT42T4F5MZCYLG5E3PV2U4FANCNFSM4HNVEA2Q .
Yes, both examples work there.
Sample values for the playground:
Rule: {"in": [1, {"var": "list"}]}
Data: {"list": [1,2,3]}
is true
Rule: {"in": [1, {"var": "list"}]}
Data: {"list": [5,2,3]}
is false
Thanks for checking, I'll try to take a look at this soon.
Looks like integer is evaluated as floating point and then:
ArrayLike(arguments.get(1)).contains(arguments.get(0));
gets 1.0
and [1, 2, 3]
and it doesn't match. So, this works:
val data2 = mapOf("list" to listOf(1.0, 2.0, 3.0))
assertEquals(true, jsonLogic.apply("""{"in": [1, {"var": "list"}]}""", data2))
@jamsesso, do you have an idea how to fix it?
I haven't had a chance to look into it yet.
@pn Can you review the above PR?
I'm trying to use
in
operator with arrays. It works with inline data but I'm not able to make it work with data object.Am I doing something wrong? Or is it a bug?