Class JsonProcessingController

java.lang.Object
com.streamconverter.controller.AbstractStreamController
com.streamconverter.controller.JsonProcessingController
All Implemented Interfaces:
IStreamController

Controller for JSON data processing operations.

This controller demonstrates advanced command pipeline configuration for JSON processing. It supports various JSON processing scenarios:

  • Property extraction using TreePath-like expressions
  • JSON formatting and pretty-printing
  • Data validation with custom rules
  • Transformation pipelines with multiple stages

Usage examples:

 // Extract property with validation
 JsonProcessingController controller = JsonProcessingController.forPropertyExtraction("user.name", true);
 controller.process(inputStream, outputStream);

 // Multi-stage transformation
 JsonProcessingController controller = JsonProcessingController.forTransformation(
     "data.items", "item-processor", "final-formatter"
 );
 controller.process(inputStream, outputStream);
 
Since:
1.0
Version:
1.0
Author:
StreamConverter Team
  • Method Details

    • forPropertyExtraction

      public static JsonProcessingController forPropertyExtraction(String propertyPath, boolean enableValidation)
      Factory method for property extraction.
      Parameters:
      propertyPath - TreePath-like expression (e.g., "user.name", "data[0].id")
      enableValidation - whether to enable validation
      Returns:
      configured controller
    • forFormatting

      Factory method for JSON formatting only.
      Returns:
      configured controller that formats JSON without extraction
    • forTransformation

      public static JsonProcessingController forTransformation(String propertyPath, String... processingStages)
      Factory method for multi-stage transformation.
      Parameters:
      propertyPath - TreePath-like expression for initial extraction
      processingStages - array of processor IDs for transformation stages
      Returns:
      configured controller
    • configureCommands

      Description copied from class: AbstractStreamController
      Configures the command pipeline for this controller.

      Subclasses must implement this method to define their specific processing pipeline. The returned CommandConfig array will be used to create the actual command objects using EnhancedCommandFactory.

      Example implementation:

       @Override
       protected CommandConfig[] configureCommands() {
           return new CommandConfig[] {
               new CommandConfig(CsvNavigateCommand.class, "data", "Extract data column"),
               new CommandConfig(CsvValidateCommand.class, "Validate output", requiredColumns)
           };
       }
       
      Specified by:
      configureCommands in class AbstractStreamController
      Returns:
      array of command configurations defining the processing pipeline
    • getInputDataType

      Description copied from interface: IStreamController
      Gets the expected input data type that this controller can handle.

      This information can be used by external systems to route data to appropriate controllers.

      Returns:
      the expected input data type (e.g., "CSV", "JSON", "XML", "BINARY")
    • getOutputDataType

      Description copied from interface: IStreamController
      Gets the output data type that this controller produces.

      This information helps external systems understand what type of data to expect from the processing.

      Returns:
      the output data type (e.g., "CSV", "JSON", "XML", "BINARY")
    • getProcessingScenario

      Gets the processing scenario.
      Returns:
      the processing scenario
    • getPropertyPath

      Gets the property path for extraction.
      Returns:
      the property path, or null if not applicable
    • isValidationEnabled

      public boolean isValidationEnabled()
      Checks if validation is enabled.
      Returns:
      true if validation is enabled
    • getProcessingStages

      Gets the processing stages for multi-stage transformation.
      Returns:
      array of processing stage IDs, or null if not applicable
    • getConfigurationDescription

      Description copied from class: AbstractStreamController
      Gets a description of the controller's current configuration.
      Specified by:
      getConfigurationDescription in interface IStreamController
      Overrides:
      getConfigurationDescription in class AbstractStreamController
      Returns:
      configuration description
    • validateConfiguration

      protected void validateConfiguration()
      Description copied from class: AbstractStreamController
      Allows subclasses to perform additional validation after configuration.

      This method is called after the command pipeline is configured but before the controller is marked as ready. Subclasses can override this to add custom validation logic.

      Overrides:
      validateConfiguration in class AbstractStreamController