From issues-return-83345-archive-asf-public=cust-asf.ponee.io@nifi.apache.org Mon Aug 26 00:15:34 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id CD249180656 for ; Mon, 26 Aug 2019 02:15:33 +0200 (CEST) Received: (qmail 78761 invoked by uid 500); 26 Aug 2019 00:15:33 -0000 Mailing-List: contact issues-help@nifi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@nifi.apache.org Delivered-To: mailing list issues@nifi.apache.org Received: (qmail 78752 invoked by uid 99); 26 Aug 2019 00:15:33 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Aug 2019 00:15:33 +0000 From: GitBox To: issues@nifi.apache.org Subject: [GitHub] [nifi] mans2singh commented on a change in pull request #3646: NIFI-6546 - Add JsonPath set value support Message-ID: <156677853296.31725.14030381301663518625.gitbox@gitbox.apache.org> Date: Mon, 26 Aug 2019 00:15:32 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit mans2singh commented on a change in pull request #3646: NIFI-6546 - Add JsonPath set value support URL: https://github.com/apache/nifi/pull/3646#discussion_r317421458 ########## File path: nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/JsonPathSetEvaluator.java ########## @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.attribute.expression.language.evaluation.functions; + +import com.jayway.jsonpath.DocumentContext; +import com.jayway.jsonpath.JsonPath; +import org.apache.nifi.attribute.expression.language.EvaluationContext; +import org.apache.nifi.attribute.expression.language.evaluation.Evaluator; +import org.apache.nifi.attribute.expression.language.evaluation.QueryResult; +import org.apache.nifi.attribute.expression.language.evaluation.StringQueryResult; + +/** + * JsonPathSetEvaluator allows setting values at the specified existing path + */ +public class JsonPathSetEvaluator extends JsonPathBaseEvaluator { + + protected Evaluator valueEvaluator; + + public JsonPathSetEvaluator(final Evaluator subject, final Evaluator jsonPathExp, final Evaluator valueEvaluator) { + super(subject, jsonPathExp); + this.valueEvaluator = valueEvaluator; + } + + @Override + public QueryResult evaluate(EvaluationContext context) { + DocumentContext documentContext = getDocumentContext(context); + final JsonPath compiledJsonPath = getJsonPath(context); + + final Object value = valueEvaluator.evaluate(context).getValue(); + + String result; + try { + result = documentContext.set(compiledJsonPath, value).jsonString(); + } catch (Exception e) { + // assume the path did not match anything in the document Review comment: Added error log ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org With regards, Apache Git Services