Class AttributesToJSON

java.lang.Object
org.apache.nifi.components.AbstractConfigurableComponent
org.apache.nifi.processor.AbstractSessionFactoryProcessor
org.apache.nifi.processor.AbstractProcessor
org.apache.nifi.processors.standard.AttributesToJSON
All Implemented Interfaces:
org.apache.nifi.components.ConfigurableComponent, org.apache.nifi.processor.Processor

@SideEffectFree @SupportsBatching @Tags({"json","attributes","flowfile"}) @InputRequirement(INPUT_REQUIRED) @CapabilityDescription("Generates a JSON representation of the input FlowFile Attributes. The resulting JSON can be written to either a new Attribute \'JSONAttributes\' or written to the FlowFile as content. Attributes which contain nested JSON objects can either be handled as JSON or as escaped JSON depending on the strategy chosen.") @WritesAttribute(attribute="JSONAttributes", description="JSON representation of Attributes") public class AttributesToJSON extends org.apache.nifi.processor.AbstractProcessor
  • Field Details

    • JSON_ATTRIBUTE_NAME

      public static final String JSON_ATTRIBUTE_NAME
      See Also:
    • AT_LIST_SEPARATOR

      private static final String AT_LIST_SEPARATOR
      See Also:
    • DESTINATION_ATTRIBUTE

      public static final String DESTINATION_ATTRIBUTE
      See Also:
    • DESTINATION_CONTENT

      public static final String DESTINATION_CONTENT
      See Also:
    • APPLICATION_JSON

      public static final String APPLICATION_JSON
      See Also:
    • ATTRIBUTES_LIST

      public static final org.apache.nifi.components.PropertyDescriptor ATTRIBUTES_LIST
    • ATTRIBUTES_REGEX

      public static final org.apache.nifi.components.PropertyDescriptor ATTRIBUTES_REGEX
    • DESTINATION

      public static final org.apache.nifi.components.PropertyDescriptor DESTINATION
    • INCLUDE_CORE_ATTRIBUTES

      public static final org.apache.nifi.components.PropertyDescriptor INCLUDE_CORE_ATTRIBUTES
    • NULL_VALUE_FOR_EMPTY_STRING

      public static final org.apache.nifi.components.PropertyDescriptor NULL_VALUE_FOR_EMPTY_STRING
    • JSON_HANDLING_STRATEGY

      public static final org.apache.nifi.components.PropertyDescriptor JSON_HANDLING_STRATEGY
    • PRETTY_PRINT

      public static final org.apache.nifi.components.PropertyDescriptor PRETTY_PRINT
    • PROPERTY_DESCRIPTORS

      private static final List<org.apache.nifi.components.PropertyDescriptor> PROPERTY_DESCRIPTORS
    • REL_SUCCESS

      public static final org.apache.nifi.processor.Relationship REL_SUCCESS
    • REL_FAILURE

      public static final org.apache.nifi.processor.Relationship REL_FAILURE
    • RELATIONSHIPS

      private static final Set<org.apache.nifi.processor.Relationship> RELATIONSHIPS
    • OBJECT_MAPPER

      private static final com.fasterxml.jackson.databind.ObjectMapper OBJECT_MAPPER
    • attributesToRemove

      private volatile Set<String> attributesToRemove
    • attributes

      private volatile Set<String> attributes
    • nullValueForEmptyString

      private volatile Boolean nullValueForEmptyString
    • destinationContent

      private volatile boolean destinationContent
    • objectWriter

      private volatile com.fasterxml.jackson.databind.ObjectWriter objectWriter
    • pattern

      private volatile Pattern pattern
    • jsonHandlingStrategy

      private volatile AttributesToJSON.JsonHandlingStrategy jsonHandlingStrategy
  • Constructor Details

    • AttributesToJSON

      public AttributesToJSON()
  • Method Details

    • getSupportedPropertyDescriptors

      protected List<org.apache.nifi.components.PropertyDescriptor> getSupportedPropertyDescriptors()
      Overrides:
      getSupportedPropertyDescriptors in class org.apache.nifi.components.AbstractConfigurableComponent
    • getRelationships

      public Set<org.apache.nifi.processor.Relationship> getRelationships()
      Specified by:
      getRelationships in interface org.apache.nifi.processor.Processor
      Overrides:
      getRelationships in class org.apache.nifi.processor.AbstractSessionFactoryProcessor
    • buildAttributesMapForFlowFile

      protected Map<String,Object> buildAttributesMapForFlowFile(org.apache.nifi.flowfile.FlowFile ff, Set<String> attributes, Set<String> attributesToRemove, boolean nullValForEmptyString, Pattern attPattern)
      Builds the Map of attributes that should be included in the JSON that is emitted from this process.
      Returns:
      Map of values that are feed to a Jackson ObjectMapper
    • buildAtrs

      private Set<String> buildAtrs(String atrList)
    • onScheduled

      @OnScheduled public void onScheduled(org.apache.nifi.processor.ProcessContext context)
    • onTrigger

      public void onTrigger(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSession session) throws org.apache.nifi.processor.exception.ProcessException
      Specified by:
      onTrigger in class org.apache.nifi.processor.AbstractProcessor
      Throws:
      org.apache.nifi.processor.exception.ProcessException
    • getFormattedAttributes

      private Map<String,Object> getFormattedAttributes(Map<String,Object> flowFileAttributes) throws com.fasterxml.jackson.core.JsonProcessingException
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException
    • isPossibleJsonArray

      private boolean isPossibleJsonArray(String value)
    • isPossibleJsonObject

      private boolean isPossibleJsonObject(String value)