mirror of https://github.com/apache/nifi.git
Encapsulating the rendering of a JsonPath result within JsonUtils
This commit is contained in:
parent
c88b427e82
commit
9a5b6d5ba2
|
@ -215,7 +215,7 @@ public class EvaluateJsonPath extends AbstractProcessor {
|
|||
}
|
||||
}
|
||||
|
||||
final String resultRepresentation = getResultRepresentation(resultHolder.get());
|
||||
final String resultRepresentation = JsonUtils.getResultRepresentation(resultHolder.get());
|
||||
switch (destination) {
|
||||
case DESTINATION_ATTRIBUTE:
|
||||
jsonPathResults.put(jsonPathAttrKey, resultRepresentation);
|
||||
|
@ -237,12 +237,4 @@ public class EvaluateJsonPath extends AbstractProcessor {
|
|||
}
|
||||
}
|
||||
|
||||
private static String getResultRepresentation(Object jsonPathResult) {
|
||||
if (JsonUtils.isJsonScalar(jsonPathResult)) {
|
||||
return jsonPathResult.toString();
|
||||
}
|
||||
return JsonUtils.JSON_PROVIDER.toJson(jsonPathResult);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -129,12 +129,7 @@ public class SplitJson extends AbstractProcessor {
|
|||
split = processSession.write(split, new OutputStreamCallback() {
|
||||
@Override
|
||||
public void process(OutputStream out) throws IOException {
|
||||
String resultSegmentContent;
|
||||
if (JsonUtils.isJsonScalar(resultSegment)) {
|
||||
resultSegmentContent = resultSegment.toString();
|
||||
} else {
|
||||
resultSegmentContent = JsonUtils.JSON_PROVIDER.toJson(resultSegment);
|
||||
}
|
||||
String resultSegmentContent = JsonUtils.getResultRepresentation(resultSegment);
|
||||
out.write(resultSegmentContent.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -46,7 +46,7 @@ import java.util.Map;
|
|||
*/
|
||||
public class JsonUtils {
|
||||
|
||||
public static final JsonProvider JSON_PROVIDER = Configuration.defaultConfiguration().jsonProvider();
|
||||
static final JsonProvider JSON_PROVIDER = Configuration.defaultConfiguration().jsonProvider();
|
||||
|
||||
public static final Validator JSON_PATH_VALIDATOR = new Validator() {
|
||||
@Override
|
||||
|
@ -116,4 +116,12 @@ public class JsonUtils {
|
|||
return !(obj instanceof Map || obj instanceof List);
|
||||
}
|
||||
|
||||
|
||||
public static String getResultRepresentation(Object jsonPathResult) {
|
||||
if (JsonUtils.isJsonScalar(jsonPathResult)) {
|
||||
return jsonPathResult.toString();
|
||||
}
|
||||
return JSON_PROVIDER.toJson(jsonPathResult);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue