NIFI-3344 Added property to JoltTransformJSON allowing the user to specify pretty print, defaults to false

Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com>

This closes #2987.
This commit is contained in:
Nick Lewis 2018-08-31 09:12:05 -05:00 committed by Pierre Villard
parent 5d3558a79d
commit db645ec475
1 changed files with 11 additions and 1 deletions

View File

@ -130,6 +130,15 @@ public class JoltTransformJSON extends AbstractProcessor {
.required(true)
.build();
public static final PropertyDescriptor PRETTY_PRINT = new PropertyDescriptor.Builder()
.name("pretty_print")
.displayName("Pretty Print")
.description("Apply pretty print formatting to the output of the Jolt transform")
.required(true)
.allowableValues("true", "false")
.defaultValue("false")
.build();
public static final Relationship REL_SUCCESS = new Relationship.Builder()
.name("success")
.description("The FlowFile with transformed content will be routed to this relationship")
@ -164,6 +173,7 @@ public class JoltTransformJSON extends AbstractProcessor {
_properties.add(MODULES);
_properties.add(JOLT_SPEC);
_properties.add(TRANSFORM_CACHE_SIZE);
_properties.add(PRETTY_PRINT);
properties = Collections.unmodifiableList(_properties);
final Set<Relationship> _relationships = new HashSet<>();
@ -275,7 +285,7 @@ public class JoltTransformJSON extends AbstractProcessor {
}
final Object transformedJson = TransformUtils.transform(transform,inputJson);
jsonString = JsonUtils.toJsonString(transformedJson);
jsonString = context.getProperty(PRETTY_PRINT).asBoolean() ? JsonUtils.toPrettyJsonString(transformedJson) : JsonUtils.toJsonString(transformedJson);
} catch (final Exception ex) {
logger.error("Unable to transform {} due to {}", new Object[] {original, ex.toString(), ex});
session.transfer(original, REL_FAILURE);