DropField.java


Overview

The `DropField` class is a simple yet focused processor within the Apache Camel Kafka integration framework. Its primary purpose is to **remove a specified field** from a JSON message body flowing through a Camel route. This class operates on JSON payloads represented as Jackson `JsonNode` objects and implements the Camel `Processor` interface, enabling seamless integration into Camel routes.

In essence, `DropField` allows users to clean or filter JSON messages by dropping unwanted or sensitive fields before further processing or routing.


Class: DropField

Package

org.apache.camel.component.kafka.transform

Implements

org.apache.camel.Processor

Description

`DropField` is a Camel `Processor` that removes a specified field from the JSON object contained in the message body. If the message body is not a JSON object, the processor performs no action. If the body is null or not convertible to JSON, it throws an `InvalidPayloadException`.

This processor is part of the **JSON Field Manipulation** utilities used in Kafka message transformation pipelines.


Constructors

1. DropField()

2. DropField(String field, String value)


Fields

Name

Type

Description

field

String

The name of the JSON field to drop from the message body.


Methods

void process(Exchange ex) throws InvalidPayloadException


void setField(String field)


Important Implementation Details


Interaction with Other Components


Usage Example in a Camel Route (Java DSL)

from("kafka:inputTopic")
    .process(new DropField("password", null))
    .to("kafka:outputTopic");

or using the setter:

DropField dropField = new DropField();
dropField.setField("password");

from("kafka:inputTopic")
    .process(dropField)
    .to("kafka:outputTopic");

This route removes the "password" field from every JSON message before sending it to the output topic.


Mermaid Class Diagram

classDiagram
    class DropField {
        -String field
        +DropField()
        +DropField(String field, String value)
        +void process(Exchange ex) throws InvalidPayloadException
        +void setField(String field)
    }
    DropField ..|> Processor

Summary

The `DropField` class is a straightforward Camel `Processor` designed for JSON payload manipulation within Kafka message pipelines. It focuses on removing a specified field from a JSON object message body safely and efficiently. Its simplicity makes it a valuable utility for filtering sensitive or unnecessary data from Kafka messages in Apache Camel routes.

By integrating `DropField` in message routes, users can enforce data privacy, reduce payload size, or prepare messages for routing without complex manual JSON handling.


Additional Notes


End of Documentation for DropField.java