Package com.streamconverter.controller
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Processing scenarios for JSON -
Method Summary
Modifier and TypeMethodDescriptionprotected CommandConfig[]
Configures the command pipeline for this controller.static JsonProcessingController
Factory method for JSON formatting only.static JsonProcessingController
forPropertyExtraction
(String propertyPath, boolean enableValidation) Factory method for property extraction.static JsonProcessingController
forTransformation
(String propertyPath, String... processingStages) Factory method for multi-stage transformation.Gets a description of the controller's current configuration.Gets the expected input data type that this controller can handle.Gets the output data type that this controller produces.Gets the processing scenario.String[]
Gets the processing stages for multi-stage transformation.Gets the property path for extraction.boolean
Checks if validation is enabled.protected void
Allows subclasses to perform additional validation after configuration.Methods inherited from class com.streamconverter.controller.AbstractStreamController
getCommandConfigs, getStreamConverter, isConfigured, process
-
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 extractionprocessingStages
- 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 classAbstractStreamController
- 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
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 interfaceIStreamController
- Overrides:
getConfigurationDescription
in classAbstractStreamController
- Returns:
- configuration description
-
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 classAbstractStreamController
-