add comstant

This commit is contained in:
Yuriy Lytvynchuk 2022-09-27 10:28:29 +03:00
parent 3c4618c8dc
commit ff89f85bd1
2 changed files with 4 additions and 3 deletions

View File

@ -57,7 +57,7 @@ public class TbJsonPathNode implements TbNode {
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
this.config = TbNodeUtils.convert(configuration, TbJsonPathNodeConfiguration.class);
this.jsonPathValue = config.getJsonPath();
if (this.jsonPathValue != "$") {
if (!TbJsonPathNodeConfiguration.DEFAULT_JSON_PATH.equals(this.jsonPathValue)) {
this.configurationJsonPath = Configuration.builder()
.jsonProvider(new JacksonJsonNodeJsonProvider())
.build();
@ -67,7 +67,7 @@ public class TbJsonPathNode implements TbNode {
@Override
public void onMsg(TbContext ctx, TbMsg msg) throws ExecutionException, InterruptedException, TbNodeException {
if (jsonPathValue != "$") {
if (!TbJsonPathNodeConfiguration.DEFAULT_JSON_PATH.equals(this.jsonPathValue)) {
try {
JsonNode jsonPathData = jsonPath.read(msg.getData(), this.configurationJsonPath);
ctx.tellSuccess(TbMsg.transformMsg(msg, msg.getType(), msg.getOriginator(), msg.getMetaData(), JacksonUtil.toString(jsonPathData)));

View File

@ -21,12 +21,13 @@ import org.thingsboard.rule.engine.api.NodeConfiguration;
@Data
public class TbJsonPathNodeConfiguration implements NodeConfiguration<TbJsonPathNodeConfiguration> {
static final String DEFAULT_JSON_PATH = "$";
private String jsonPath;
@Override
public TbJsonPathNodeConfiguration defaultConfiguration() {
TbJsonPathNodeConfiguration configuration = new TbJsonPathNodeConfiguration();
configuration.setJsonPath("$");
configuration.setJsonPath(DEFAULT_JSON_PATH);
return configuration;
}