diff --git a/java/json-transform/build.gradle b/java/json-transform/build.gradle index 246e664..0d5a299 100644 --- a/java/json-transform/build.gradle +++ b/java/json-transform/build.gradle @@ -9,7 +9,7 @@ plugins { } group 'co.nlighten' -version = '0.2.1' +version = '0.2.3' ext { gsonVersion = "2.10.1" diff --git a/java/json-transform/src/main/java/co/nlighten/jsontransform/JsonTransformer.java b/java/json-transform/src/main/java/co/nlighten/jsontransform/JsonTransformer.java index 77d4f84..cc107a4 100644 --- a/java/json-transform/src/main/java/co/nlighten/jsontransform/JsonTransformer.java +++ b/java/json-transform/src/main/java/co/nlighten/jsontransform/JsonTransformer.java @@ -11,6 +11,7 @@ public abstract class JsonTransformer, JO extends JE> implements Transformer { static final String OBJ_DESTRUCT_KEY = "*"; + static final String FUNCTION_PREFIX = "$$"; private final JsonAdapter adapter; protected final JE definition; diff --git a/java/json-transform/src/main/java/co/nlighten/jsontransform/JsonTransformerUtils.java b/java/json-transform/src/main/java/co/nlighten/jsontransform/JsonTransformerUtils.java index 713ebda..5d78f57 100644 --- a/java/json-transform/src/main/java/co/nlighten/jsontransform/JsonTransformerUtils.java +++ b/java/json-transform/src/main/java/co/nlighten/jsontransform/JsonTransformerUtils.java @@ -26,7 +26,6 @@ private static , JO extends JE> void findAllVariable var matcher = variableDetectionRegExp.matcher(string); while (matcher.find()) { var v = matcher.group(); - if (v.endsWith("$$")) v = v.substring(0, v.length() - 2); if (!result.containsKey(v)) result.put(v, path); } } else if (adapter.jArray.is(element)) { @@ -37,9 +36,14 @@ private static , JO extends JE> void findAllVariable } } else if (adapter.jObject.is(element)) { var coll = adapter.jObject.type.cast(element); + var isObjectFunction = adapter.jObject.keySet(coll).stream().anyMatch(x -> x.startsWith("$$")); adapter.jObject.keySet(coll).forEach(x -> { var value = adapter.jObject.get(coll, x); - findAllVariableUses(adapter, value, result, JsonTransformer.OBJ_DESTRUCT_KEY.equals(x) ? path : path + "." + x); + findAllVariableUses(adapter, value, result, + JsonTransformer.OBJ_DESTRUCT_KEY.equals(x) || isObjectFunction + ? path + : path + "." + x + ); }); } } diff --git a/java/json-transform/src/test/java/co/nlighten/jsontransform/JsonTransformerUtilsTest.java b/java/json-transform/src/test/java/co/nlighten/jsontransform/JsonTransformerUtilsTest.java index 274cf84..71bffa2 100644 --- a/java/json-transform/src/test/java/co/nlighten/jsontransform/JsonTransformerUtilsTest.java +++ b/java/json-transform/src/test/java/co/nlighten/jsontransform/JsonTransformerUtilsTest.java @@ -110,5 +110,21 @@ void strings() { "$.input2", "$", "#now", "$" ), result); + + result = JsonTransformerUtils.findAllVariableUses(adapter, adapter.parse(""" + { + "filters": { + "locked": { + "$$map": "$.parameters.locked$$", + "to": "$$boolean:##current", + "x_target": "$.parameters.x_source" + } + } + } +""")); + Assertions.assertEquals(Map.of( + "$.parameters.locked$$", "$.filters.locked", + "$.parameters.x_source", "$.filters.locked" + ), result); } }