Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #4646] Add condition for transforming non-data values #4637

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add condition for transforming non-data values
  • Loading branch information
pmupkin committed Dec 11, 2023
commit fdd87969e34e6e831a420aeb9cfbc6776ecaeec7
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,18 @@ public JsonPathParser(String jsonPathString) {
Map.Entry<String, JsonNode> entry = fields.next();
String name = entry.getKey();
JsonNode valueNode = entry.getValue();
if (valueNode.isValueNode()) {
variablesList.add(new Variable(name, valueNode.asText()));
} else {
throw new TransformException("invalid config:" + jsonPathString);

if (!valueNode.isValueNode()) {
throw new TransformException("invalid config: " + jsonPathString);
}

String valueText = valueNode.asText();
if (valueText.startsWith("$") && !valueText.startsWith("$.data")) {
throw new TransformException("invalid config: unsupported value " + jsonPathString);
}

variablesList.add(new Variable(name, valueText));

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,14 @@ public void testTemplateTransFormerWithConstant() throws JsonProcessingException
output);
}

@Test
public void testTemplateTransFormerWithNonDataItem() {
String extractJson = "{\"name\":\"$.data.name\",\"time\":\"$.time\"" + "}";
String template = "Transformers test:data name is ${name}, time is ${time}";
Throwable exception = Assertions.assertThrows(TransformException.class, ()->TransformerBuilder.buildTemplateTransFormer(extractJson, template));
Assertions.assertEquals("invalid config: unsupported value {\"name\":\"$.data.name\",\"time\":\"$.time\"}" , exception.getMessage());
}



}
Loading