Skip to content

Commit

Permalink
NIFI-3344 Added property to JoltTransformJSON allowing the user to sp…
Browse files Browse the repository at this point in the history
…ecify pretty print, defaults to false

Signed-off-by: Pierre Villard <[email protected]>

This closes apache#2987.
  • Loading branch information
nalewis authored and pvillard31 committed Sep 25, 2018
1 parent 5d3558a commit db645ec
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -164,6 +173,7 @@ protected boolean removeEldestEntry(Map.Entry<String, JoltTransform> eldest) {
_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<>();
Expand Down Expand Up @@ -275,7 +285,7 @@ public void onTrigger(final ProcessContext context, ProcessSession session) thro
}

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);
Expand Down

0 comments on commit db645ec

Please sign in to comment.