bazaarvoice / jolt

JSON to JSON transformation library written in Java.
Apache License 2.0
1.54k stars 328 forks source link

Spec works in tester, not in Java #1129

Closed oset-bschuhma closed 2 years ago

oset-bschuhma commented 2 years ago

Hi - I've got a really simple input json and spec. They work fine in the tester app, but when I run it in my Java code I just get the input json back, untouched.

Input: { "foo": "bar", "id": "page-15b0a89b99" }

Spec: [{ "operation": "remove", "spec": { "id": "", ":items": "", ":type": "", "designPath": "" } }, { "operation": "sort" }]

Expected output: { "foo" : "bar" }

I get the original input back... here's a logfile where I spit out each piece to verify it: ] com.someco.acs.core.servlets.JoltObjectModelServlet readJoltSpec... spec is[{"operation":"remove","spec":{"id":"", ":items":"",":type":"","designPath":""}},{"operation":"sort"}] 2 22.04.2022 12:47:28.202 *DEBUG* [0:0:0:0:0:0:0:1 [1650646048119] GET /content/we-retail/us/en/men.jolt.html HTTP/1.1 ] com.someco.acs.core.servlets.JoltObjectModelServlet applyJoltTransform... slingModel is: { "foo": "bar", "id": "page-15b0a89b99"} 105 22.04.2022 12:47:28.202 *DEBUG* [0:0:0:0:0:0:0:1 [1650646048119] GET /content/we-retail/us/en/men.jolt.html HTTP/1.1 ] com.someco.acs.core.servlets.JoltObjectModelServlet applyJoltTransform... (not jsonified) transformed output is: { "foo": "bar", "id": "page-15b0a89b99"}

This is a super simple version of what I'm trying to accomplish - in reality I'm reading a sling model of a web page, retrieving a jolt spec from the web server (stored next to the page), then applying the spec and presenting it to the user. If I had to guess I'd say jolt is not finding any of the fields I'm trying to remove in the input - i.e. it doesn't see the "id" in the input json. But how can that be? Hidden characters somehow? Should I be specifying a charset or something? Oddities via retrieving the spec from the web server?

Any suggestions gratefully received! Thanks!

oset-bschuhma commented 2 years ago

I got this working, though I don't recall what the fix was at this point. I think it had to with me using prettified JSON instead of the raw string I read from the file, the keys weren't recognized, so the whole transformation was skipped.