You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "atiaomar1978-hub (via GitHub)" <gi...@apache.org> on 2026/08/13 18:47:10 UTC

[PR] CAMEL-24377: Add JSON support to CamelEvent [camel]

atiaomar1978-hub opened a new pull request, #25495:
URL: https://github.com/apache/camel/pull/25495

   ## Description
   
   Implements [CAMEL-24377](https://issues.apache.org/jira/browse/CAMEL-24377): structured JSON serialization for `CamelEvent`, similar to the existing `BacklogEventMessage` API used by Error Registry and Backlog Tracer.
   
   ### API
   
   Added to `org.apache.camel.spi.CamelEvent`:
   
   - `Map<String, Object> asJSon()` — structured event metadata as a JSON-compatible map
   - `String toJSon(int indent)` — pretty-printed JSON string
   
   ### Implementation
   
   - `CamelEventJsonSupport` in `camel-base` builds JSON for all standard event types (context, route, exchange, step, service, failure)
   - Abstract event base classes and service failure events delegate to the support class
   - `EventConsole` now uses `event.asJSon()` instead of ad hoc `toString()` fields
   
   ### JSON fields (examples)
   
   | Event category | Fields |
   |----------------|--------|
   | All events | `type`, `eventClass`, `timestamp`, `message` |
   | Context | `contextName` |
   | Route | `routeId`, `routeGroup`, `fromEndpointUri` |
   | Exchange | `exchangeId`, `fromRouteId`, `routeId` |
   | Sent/Sending | `endpointUri`, `timeTaken` (sent) |
   | Failure | `exception` (type, message, stackTrace) |
   | Redelivery | `attempt`, `exception` |
   | Step | `stepId` |
   | Service failure | `service`, `contextName` |
   
   ### Tests
   
   `CamelEventJsonTest` covers context, exchange failed/sent/failure-handling/redelivery, route reloaded/restarting failure, step failed, and service startup failure events.
   
   ```bash
   ./mvnw -pl core/camel-core -am test -Dtest=CamelEventJsonTest -Dsurefire.failIfNoSpecifiedTests=false
   ```
   
   ### Documentation
   
   Updated `docs/user-manual/modules/ROOT/pages/event-notifier.adoc` with JSON serialization section.
   
   ## Tracking
   
   - [x] [CAMEL-24377](https://issues.apache.org/jira/browse/CAMEL-24377)
   
   ## AI-assisted contributions
   
   _AI-generated PR on behalf of atiaomar1978-hub (Cursor Agent)_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24377: Add JSON support to CamelEvent [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #25495:
URL: https://github.com/apache/camel/pull/25495#discussion_r3917740208


##########
core/camel-api/src/main/java/org/apache/camel/spi/CamelEvent.java:
##########
@@ -94,6 +96,22 @@ enum Type {
 
     void setTimestamp(long timestamp);
 
+    /**
+     * Dumps the full event as a pretty-printed JSON string.
+     *
+     * @param  indent number of spaces to indent
+     * @return        JSON representation of this event
+     * @since         4.23
+     */
+    String toJSon(int indent);
+
+    /**
+     * The full event as a {@link Map} suitable for JSON serialization, containing structured metadata for this event.
+     *
+     * @since 4.23
+     */
+    Map<String, Object> asJSon();

Review Comment:
   `CamelEvent` is a published SPI, and these two methods are added as **non-`default`** abstract methods. That's a source- and binary-incompatible change for any code outside Camel that implements `CamelEvent` (or one of its sub-interfaces) directly — it will no longer compile/link. `project-standards.md` requires maintaining backwards compatibility for public APIs.
   
   All in-tree events extend the modified abstract base classes, so the internal build is fine — the risk is entirely external.
   
   Suggest making both methods `default` so existing implementers keep working. Since `CamelEventJsonSupport` lives in `camel-base` (not reachable from `camel-api`), a reasonable default is a minimal map here (e.g. `type`/`timestamp`/`message`), with the rich implementation remaining the override in `AbstractContextEvent`/`AbstractExchangeEvent`/`AbstractRouteEvent`/etc. If a hard SPI break is genuinely intended, it needs explicit justification and an upgrade-guide entry.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24377: Add JSON support to CamelEvent [camel]

Posted by "atiaomar1978-hub (via GitHub)" <gi...@apache.org>.
atiaomar1978-hub commented on PR #25495:
URL: https://github.com/apache/camel/pull/25495#issuecomment-5546436818

   ## All review feedback addressed — ready for re-review
   
   _Cursor Agent on behalf of atiaomar1978-hub (AI-generated)_
   
   Thanks @davsclaus @gnodet — summary of fixes on the latest head (`a40734b`):
   
   | Review item | Commit | Status |
   |-------------|--------|--------|
   | Make `asJSon()` / `toJSon()` **default methods** (SPI compatibility) | `6c7b7bc` | Done |
   | Regenerate dev-console `event.json` descriptor for `details` field | `ad1b12d` | Done |
   | Upgrade guide entry in `camel-4x-upgrade-guide-4_23.adoc` | `6c7b7bc` | Done |
   | JSON-escape default `toJSon()` output (`StringQuoteHelper.jsonQuote()`) | `c32249aeb05` | Done |
   | Test default SPI path with special characters in `toString()` | `c32249aeb05` | Done |
   | Document scalar-only constraint for default `toJSon()` | `a40734b` | Done |
   
   **CI:** green on Java 17/25 and doc validation (latest run on `c32249aeb05`).
   
   All inline review threads are resolved. @davsclaus could you take another look when you have a moment?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24377: Add JSON support to CamelEvent [camel]

Posted by "atiaomar1978-hub (via GitHub)" <gi...@apache.org>.
atiaomar1978-hub commented on code in PR #25495:
URL: https://github.com/apache/camel/pull/25495#discussion_r3926901021


##########
core/camel-api/src/main/java/org/apache/camel/spi/CamelEvent.java:
##########
@@ -94,6 +98,63 @@ enum Type {
 
     void setTimestamp(long timestamp);
 
+    /**
+     * Dumps the full event as a pretty-printed JSON string.
+     *
+     * @param  indent number of spaces to indent
+     * @return        JSON representation of this event
+     * @since         4.23
+     */
+    default String toJSon(int indent) {
+        Map<String, Object> map = asJSon();
+        String indentText = indent > 0 ? " ".repeat(indent) : "";
+        StringBuilder sb = new StringBuilder(128);
+        sb.append('{');
+        boolean first = true;
+        for (Map.Entry<String, Object> entry : map.entrySet()) {
+            if (!first) {
+                sb.append(',');
+            }
+            first = false;
+            if (indent > 0) {
+                sb.append('\n').append(indentText);
+            }
+            sb.append(StringQuoteHelper.doubleQuote(entry.getKey())).append(':');
+            if (indent > 0) {
+                sb.append(' ');
+            }
+            Object value = entry.getValue();
+            if (value instanceof Number || value instanceof Boolean) {
+                sb.append(value);
+            } else {
+                sb.append(StringQuoteHelper.doubleQuote(String.valueOf(value)));

Review Comment:
   Fixed in `c32249aeb05` — implemented `StringQuoteHelper.jsonQuote()` in `camel-util` as suggested, and updated the default `CamelEvent.toJSon()` to use it for both keys and string values.
   
   _Cursor Agent on behalf of atiaomar1978-hub_



##########
core/camel-api/src/main/java/org/apache/camel/spi/CamelEvent.java:
##########
@@ -94,6 +98,63 @@ enum Type {
 
     void setTimestamp(long timestamp);
 
+    /**
+     * Dumps the full event as a pretty-printed JSON string.
+     *
+     * @param  indent number of spaces to indent
+     * @return        JSON representation of this event
+     * @since         4.23
+     */
+    default String toJSon(int indent) {
+        Map<String, Object> map = asJSon();
+        String indentText = indent > 0 ? " ".repeat(indent) : "";
+        StringBuilder sb = new StringBuilder(128);
+        sb.append('{');
+        boolean first = true;
+        for (Map.Entry<String, Object> entry : map.entrySet()) {
+            if (!first) {
+                sb.append(',');
+            }
+            first = false;
+            if (indent > 0) {
+                sb.append('\n').append(indentText);
+            }
+            sb.append(StringQuoteHelper.doubleQuote(entry.getKey())).append(':');
+            if (indent > 0) {
+                sb.append(' ');
+            }
+            Object value = entry.getValue();
+            if (value instanceof Number || value instanceof Boolean) {
+                sb.append(value);
+            } else {
+                sb.append(StringQuoteHelper.doubleQuote(String.valueOf(value)));

Review Comment:
   Fixed in `c32249aeb05` — added `StringQuoteHelper.jsonQuote()` in `camel-util` with proper JSON escaping and switched the default `CamelEvent.toJSon()` to use it for keys and string values. Added `CamelEventJsonTest.testDefaultCamelEventToJsonEscapesSpecialCharacters` covering the default SPI path with `\"` and newlines in `toString()`.
   
   _Cursor Agent on behalf of atiaomar1978-hub_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24377: Add JSON support to CamelEvent [camel]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #25495:
URL: https://github.com/apache/camel/pull/25495#discussion_r3925182991


##########
core/camel-api/src/main/java/org/apache/camel/spi/CamelEvent.java:
##########
@@ -94,6 +98,63 @@ enum Type {
 
     void setTimestamp(long timestamp);
 
+    /**
+     * Dumps the full event as a pretty-printed JSON string.
+     *
+     * @param  indent number of spaces to indent
+     * @return        JSON representation of this event
+     * @since         4.23
+     */
+    default String toJSon(int indent) {
+        Map<String, Object> map = asJSon();
+        String indentText = indent > 0 ? " ".repeat(indent) : "";
+        StringBuilder sb = new StringBuilder(128);
+        sb.append('{');
+        boolean first = true;
+        for (Map.Entry<String, Object> entry : map.entrySet()) {
+            if (!first) {
+                sb.append(',');
+            }
+            first = false;
+            if (indent > 0) {
+                sb.append('\n').append(indentText);
+            }
+            sb.append(StringQuoteHelper.doubleQuote(entry.getKey())).append(':');
+            if (indent > 0) {
+                sb.append(' ');
+            }
+            Object value = entry.getValue();
+            if (value instanceof Number || value instanceof Boolean) {
+                sb.append(value);
+            } else {
+                sb.append(StringQuoteHelper.doubleQuote(String.valueOf(value)));

Review Comment:
   `StringQuoteHelper.doubleQuote(String.valueOf(value))` does not JSON-escape — it's literally `'"' + text + '"'`. Any value containing `"`, `\`, or control chars produces invalid JSON.
   
   Minimal fix — add a proper JSON escape to `StringQuoteHelper` (or inline here):
   
   ```suggestion
                   sb.append(jsonQuote(String.valueOf(value)));
   ```
   
   With a helper like:
   ```java
   private static String jsonQuote(String text) {
       StringBuilder sb = new StringBuilder(text.length() + 2);
       sb.append('"');
       for (int i = 0; i < text.length(); i++) {
           char c = text.charAt(i);
           switch (c) {
               case '"': sb.append("\\\"")); break;
               case '\\': sb.append("\\\\"); break;
               case '\n': sb.append("\\n"); break;
               case '\r': sb.append("\\r"); break;
               case '\t': sb.append("\\t"); break;
               default:
                   if (c < 0x20) sb.append(String.format("\\u%04x", (int) c));
                   else sb.append(c);
           }
       }
       sb.append('"');
       return sb.toString();
   }
   ```
   
   The same escaping must also be applied to the key on line 118 (`StringQuoteHelper.doubleQuote(entry.getKey())`).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24377: Add JSON support to CamelEvent [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #25495:
URL: https://github.com/apache/camel/pull/25495#issuecomment-5427225738

   :star2: Thank you for your contribution to the Apache Camel project! :star2:
     :robot: CI automation will test this PR automatically.
   
     :camel: Apache Camel Committers, please review the following items:
   
     * First-time contributors **require MANUAL approval** for the GitHub Actions to run
     * You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot although they are normally detected and executed by CI.
     * You can label PRs using `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
     * Build and test logs are available in the summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary.
     
     :warning: Be careful when sharing logs. Review their contents before sharing them publicly.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24377: Add JSON support to CamelEvent [camel]

Posted by "atiaomar1978-hub (via GitHub)" <gi...@apache.org>.
atiaomar1978-hub commented on PR #25495:
URL: https://github.com/apache/camel/pull/25495#issuecomment-5515164164

   ## Review feedback addressed
   
   _Composer on behalf of atiaomar1978-hub (AI-generated)_
   
   Thanks @davsclaus — all review items are now addressed in **6c7b7bc**:
   
   | Priority | Item | Status |
   |----------|------|--------|
   | Blocking | Regenerate dev-console descriptor for `details` field | **Done** in `ad1b12d` |
   | Major | Make `asJSon()` / `toJSon()` **default methods** on `CamelEvent` SPI | **Done** in `6c7b7bc` — minimal `type`/`timestamp`/`message` fallback; built-in events still override with rich JSON via `CamelEventJsonSupport` |
   | Minor | Upgrade guide entry | **Done** in `6c7b7bc` — `camel-4x-upgrade-guide-4_23.adoc` |
   | Minor | `details` duplicates flat fields | **Intentional** — flat fields kept for backwards compatibility; `details` holds the full structured JSON payload |
   
   ### CI / regen check
   
   Re-ran locally after the latest changes:
   
   ```bash
   mvn install -pl core/camel-console,catalog/camel-catalog -am -DskipTests
   mvn test -pl core/camel-core -am -Dtest=CamelEventJsonTest -Dsurefire.failIfNoSpecifiedTests=false
   ```
   
   No uncommitted generated files — dev-console metadata from the earlier regen commit is still current.
   
   Ready for re-review.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24377: Add JSON support to CamelEvent [camel]

Posted by "atiaomar1978-hub (via GitHub)" <gi...@apache.org>.
atiaomar1978-hub commented on PR #25495:
URL: https://github.com/apache/camel/pull/25495#issuecomment-5529363227

   Addressed the blocking JSON-escaping review in `c32249aeb05`:
   
   - Added `StringQuoteHelper.jsonQuote()` in `camel-util` with proper escaping of `\"`, `\\`, control characters
   - Default `CamelEvent.toJSon()` now uses `jsonQuote` for keys and string values (replacing `doubleQuote`)
   - Added `CamelEventJsonTest.testDefaultCamelEventToJsonEscapesSpecialCharacters` for the default SPI path
   
   Built-in events unchanged (still delegate to `CamelEventJsonSupport` → `Jsoner`).
   
   _Cursor Agent on behalf of atiaomar1978-hub_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24377: Add JSON support to CamelEvent [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #25495:
URL: https://github.com/apache/camel/pull/25495#issuecomment-5521217064

   <!-- ci-tested-modules -->
   :test_tube: **CI tested the following changed modules:**
   
   - `catalog/camel-catalog`
   - `core/camel-api`
   - `core/camel-base`
   - `core/camel-console`
   - `core/camel-core`
   - `docs`
   
   > :information_source: Dependent modules were not tested because the total number of affected modules exceeded the threshold (50). Use the `test-dependents` label to force testing all dependents.
   
   ---
   
   <details><summary>:microscope: Scalpel shadow comparison — Scalpel: 567 tested, 25 compile-only — current: 565 all tested</summary>
   
   [Maveniverse Scalpel](https://github.com/maveniverse/scalpel) detected **592 affected modules** (current approach: 565).
   
   <details><summary>:warning: Modules only in Scalpel (27)</summary>
   
   - `apache-camel`
   - `camel-allcomponents`
   - `camel-catalog`
   - `camel-catalog-console`
   - `camel-catalog-maven`
   - `camel-catalog-suggest`
   - `camel-componentdsl`
   - `camel-endpointdsl`
   - `camel-endpointdsl-support`
   - `camel-itest`
   - `camel-jbang-core`
   - `camel-jbang-it`
   - `camel-jbang-main`
   - `camel-jbang-plugin-edit`
   - `camel-jbang-plugin-generate`
   - `camel-jbang-plugin-kubernetes`
   - `camel-jbang-plugin-test`
   - `camel-kamelet-main`
   - `camel-launcher`
   - `camel-report-maven-plugin`
   - `camel-route-parser`
   - `camel-yaml-dsl`
   - `camel-yaml-dsl-deserializers`
   - `camel-yaml-dsl-maven-plugin`
   - `coverage`
   - `docs`
   - `dummy-component`
   
   </details>
   
   **Skip-tests mode would test 567 modules** (6 direct + 561 downstream), **skip tests for 25** (generated code, meta-modules)
   
   <details><summary>Modules Scalpel would test (567)</summary>
   
   - `archetypes`
   - `camel-a2a`
   - `camel-activemq`
   - `camel-activemq6`
   - `camel-ai-observability`
   - `camel-ai-observability-api`
   - `camel-ai-parent`
   - `camel-ai-resource`
   - `camel-ai-tool`
   - `camel-alibaba-common`
   - `camel-alibaba-eventbridge`
   - `camel-alibaba-fc`
   - `camel-alibaba-kms`
   - `camel-alibaba-mns`
   - `camel-alibaba-oss`
   - `camel-alibaba-ots`
   - `camel-alibaba-parent`
   - `camel-alibaba-sls`
   - `camel-alibaba-sms`
   - `camel-amqp`
   - `camel-api`
   - `camel-api-component-maven-plugin`
   - `camel-arangodb`
   - `camel-archetype-api-component`
   - `camel-archetype-component`
   - `camel-archetype-dataformat`
   - `camel-archetype-java`
   - `camel-archetype-main`
   - `camel-as2`
   - `camel-as2-api`
   - `camel-as2-parent`
   - `camel-asn1`
   - `camel-asterisk`
   - `camel-atmosphere-websocket`
   - `camel-atom`
   - `camel-attachments`
   - `camel-avro`
   - `camel-avro-rpc`
   - `camel-avro-rpc-jetty`
   - `camel-avro-rpc-parent`
   - `camel-avro-rpc-spi`
   - `camel-aws-bedrock`
   - `camel-aws-cloudtrail`
   - `camel-aws-common`
   - `camel-aws-config`
   - `camel-aws-parameter-store`
   - `camel-aws-parent`
   - `camel-aws-secrets-manager`
   - `camel-aws-security-hub`
   - `camel-aws2-athena`
   - `camel-aws2-comprehend`
   - `camel-aws2-cw`
   - `camel-aws2-ddb`
   - `camel-aws2-ec2`
   - `camel-aws2-ecs`
   - `camel-aws2-eks`
   - `camel-aws2-eventbridge`
   - `camel-aws2-iam`
   - `camel-aws2-kinesis`
   - `camel-aws2-kms`
   - `camel-aws2-lambda`
   - `camel-aws2-mq`
   - `camel-aws2-msk`
   - `camel-aws2-polly`
   - `camel-aws2-redshift`
   - `camel-aws2-rekognition`
   - `camel-aws2-s3`
   - `camel-aws2-s3-vectors`
   - `camel-aws2-ses`
   - `camel-aws2-sns`
   - `camel-aws2-sqs`
   - `camel-aws2-step-functions`
   - `camel-aws2-sts`
   - `camel-aws2-textract`
   - `camel-aws2-timestream`
   - `camel-aws2-transcribe`
   - `camel-aws2-translate`
   - `camel-azure-common`
   - `camel-azure-cosmosdb`
   - `camel-azure-eventgrid`
   - `camel-azure-eventhubs`
   - `camel-azure-files`
   - `camel-azure-functions`
   - `camel-azure-key-vault`
   - `camel-azure-parent`
   - `camel-azure-schema-registry`
   - `camel-azure-servicebus`
   - `camel-azure-storage-blob`
   - `camel-azure-storage-datalake`
   - `camel-azure-storage-queue`
   - `camel-barcode`
   - `camel-base`
   - `camel-base-engine`
   - `camel-base64`
   - `camel-bean`
   - `camel-bean-validator`
   - `camel-beanio`
   - `camel-bindy`
   - `camel-bonita`
   - `camel-box`
   - `camel-box-api`
   - `camel-box-parent`
   - `camel-braintree`
   - `camel-browse`
   - `camel-caffeine`
   - `camel-camunda`
   - `camel-cassandraql`
   - `camel-catalog`
   - `camel-catalog-common`
   - `camel-cbor`
   - `camel-chatscript`
   - `camel-chunk`
   - `camel-cli-connector`
   - `camel-cli-debug`
   - `camel-clickhouse`
   - `camel-clickup`
   - `camel-cloudevents`
   - `camel-cluster`
   - `camel-cm-sms`
   - `camel-coap`
   - `camel-cometd`
   - `camel-console`
   - `camel-consul`
   - `camel-controlbus`
   - `camel-core`
   - `camel-core-all`
   - `camel-core-catalog`
   - `camel-core-engine`
   - `camel-core-languages`
   - `camel-core-model`
   - `camel-core-processor`
   - `camel-core-reifier`
   - `camel-core-xml`
   - `camel-couchbase`
   - `camel-couchdb`
   - `camel-cron`
   - `camel-crypto`
   - `camel-crypto-pgp`
   - `camel-csv`
   - `camel-cxf-common`
   - `camel-cxf-parent`
   - `camel-cxf-rest`
   - `camel-cxf-soap`
   - `camel-cxf-spring-common`
   - `camel-cxf-spring-rest`
   - `camel-cxf-spring-soap`
   - `camel-cxf-spring-transport`
   - `camel-cxf-transport`
   - `camel-cyberark-vault`
   - `camel-dapr`
   - `camel-dataformat`
   - `camel-dataset`
   - `camel-datasonnet`
   - `camel-dataweave`
   - `camel-debezium-common`
   - `camel-debezium-common-parent`
   - `camel-debezium-db2`
   - `camel-debezium-maven-plugin`
   - `camel-debezium-mongodb`
   - `camel-debezium-mysql`
   - `camel-debezium-oracle`
   - `camel-debezium-parent`
   - `camel-debezium-postgres`
   - `camel-debezium-sqlserver`
   - `camel-debug`
   - `camel-dfdl`
   - `camel-dhis2`
   - `camel-dhis2-api`
   - `camel-dhis2-parent`
   - `camel-diagram`
   - `camel-direct`
   - `camel-disruptor`
   - `camel-djl`
   - `camel-dns`
   - `camel-docker`
   - `camel-docling`
   - `camel-drill`
   - `camel-dropbox`
   - `camel-dsl-modeline`
   - `camel-dsl-support`
   - `camel-duckdb`
   - `camel-dynamic-router`
   - `camel-ehcache`
   - `camel-elasticsearch`
   - `camel-elasticsearch-rest-client`
   - `camel-event`
   - `camel-exec`
   - `camel-fastjson`
   - `camel-fhir`
   - `camel-fhir-api`
   - `camel-fhir-parent`
   - `camel-file`
   - `camel-file-watch`
   - `camel-flatpack`
   - `camel-flink`
   - `camel-flowable`
   - `camel-fop`
   - `camel-fory`
   - `camel-freemarker`
   - `camel-ftp`
   - `camel-ftp-common`
   - `camel-geocoder`
   - `camel-git`
   - `camel-github2`
   - `camel-google-bigquery`
   - `camel-google-calendar`
   - `camel-google-common`
   - `camel-google-drive`
   - `camel-google-firestore`
   - `camel-google-functions`
   - `camel-google-mail`
   - `camel-google-parent`
   - `camel-google-pubsub`
   - `camel-google-secret-manager`
   - `camel-google-sheets`
   - `camel-google-speech-to-text`
   - `camel-google-storage`
   - `camel-google-text-to-speech`
   - `camel-google-vertexai`
   - `camel-google-vision`
   - `camel-graphql`
   - `camel-grok`
   - `camel-groovy`
   - `camel-grpc`
   - `camel-gson`
   - `camel-hashicorp-vault`
   - `camel-hazelcast`
   - `camel-health`
   - `camel-hivemq`
   - `camel-hl7`
   - `camel-http`
   - `camel-http-base`
   - `camel-http-common`
   - `camel-huawei-parent`
   - `camel-huaweicloud-common`
   - `camel-huaweicloud-dms`
   - `camel-huaweicloud-frs`
   - `camel-huaweicloud-functiongraph`
   - `camel-huaweicloud-iam`
   - `camel-huaweicloud-imagerecognition`
   - `camel-huaweicloud-obs`
   - `camel-huaweicloud-smn`
   - `camel-huggingface`
   - `camel-ibm-cos`
   - `camel-ibm-parent`
   - `camel-ibm-secrets-manager`
   - `camel-ibm-watson-discovery`
   - `camel-ibm-watson-language`
   - `camel-ibm-watson-speech-to-text`
   - `camel-ibm-watson-text-to-speech`
   - `camel-ibm-watsonx-ai`
   - `camel-ibm-watsonx-data`
   - `camel-ical`
   - `camel-iggy`
   - `camel-ignite`
   - `camel-infinispan`
   - `camel-infinispan-common`
   - `camel-infinispan-embedded`
   - `camel-infinispan-parent`
   - `camel-influxdb`
   - `camel-influxdb2`
   - `camel-iso8583`
   - `camel-jackson`
   - `camel-jackson-avro`
   - `camel-jackson-protobuf`
   - `camel-jackson3`
   - `camel-jackson3-avro`
   - `camel-jackson3-protobuf`
   - `camel-jackson3xml`
   - `camel-jacksonxml`
   - `camel-jactl`
   - `camel-jandex`
   - `camel-jasypt`
   - `camel-java-io`
   - `camel-java-joor-dsl`
   - `camel-javascript`
   - `camel-jaxb`
   - `camel-jbang-console`
   - `camel-jbang-mcp`
   - `camel-jbang-plugin-mcp`
   - `camel-jbang-plugin-route-parser`
   - `camel-jbang-plugin-tui`
   - `camel-jbang-plugin-validate`
   - `camel-jcache`
   - `camel-jcr`
   - `camel-jdbc`
   - `camel-jetty`
   - `camel-jetty-common`
   - `camel-jfr`
   - `camel-jgroups`
   - `camel-jgroups-raft`
   - `camel-jira`
   - `camel-jms`
   - `camel-jmx`
   - `camel-jolt`
   - `camel-jooq`
   - `camel-joor`
   - `camel-jpa`
   - `camel-jq`
   - `camel-jsch`
   - `camel-jslt`
   - `camel-json-validator`
   - `camel-jsonapi`
   - `camel-jsonata`
   - `camel-jsonb`
   - `camel-jsonpath`
   - `camel-jsoup`
   - `camel-jt400`
   - `camel-jta`
   - `camel-jte`
   - `camel-kafka`
   - `camel-kamelet`
   - `camel-kamelet-main-support`
   - `camel-keycloak`
   - `camel-knative`
   - `camel-knative-api`
   - `camel-knative-http`
   - `camel-knative-parent`
   - `camel-kserve`
   - `camel-kubernetes`
   - `camel-kudu`
   - `camel-langchain4j-agent`
   - `camel-langchain4j-agent-api`
   - `camel-langchain4j-chat`
   - `camel-langchain4j-core`
   - `camel-langchain4j-embeddings`
   - `camel-langchain4j-embeddingstore`
   - `camel-langchain4j-embeddingstore-api`
   - `camel-langchain4j-tokenizer`
   - `camel-langchain4j-web-search`
   - `camel-language`
   - `camel-launcher-container`
   - `camel-ldap`
   - `camel-ldif`
   - `camel-log`
   - `camel-lra`
   - `camel-lucene`
   - `camel-lumberjack`
   - `camel-lzf`
   - `camel-mail`
   - `camel-mail-microsoft-oauth`
   - `camel-main`
   - `camel-management`
   - `camel-management-api`
   - `camel-mapstruct`
   - `camel-master`
   - `camel-maven-plugin`
   - `camel-mcp-server`
   - `camel-mcp-server-api`
   - `camel-mdc`
   - `camel-metrics`
   - `camel-micrometer`
   - `camel-micrometer-observability`
   - `camel-micrometer-prometheus`
   - `camel-microprofile-config`
   - `camel-microprofile-fault-tolerance`
   - `camel-microprofile-health`
   - `camel-microprofile-parent`
   - `camel-milo`
   - `camel-milvus`
   - `camel-mina`
   - `camel-mina-sftp`
   - `camel-minio`
   - `camel-mllp`
   - `camel-mock`
   - `camel-mongodb`
   - `camel-mongodb-gridfs`
   - `camel-mustache`
   - `camel-mvel`
   - `camel-mybatis`
   - `camel-nats`
   - `camel-neo4j`
   - `camel-netty`
   - `camel-netty-http`
   - `camel-oaipmh`
   - `camel-oauth`
   - `camel-observability-services`
   - `camel-observation`
   - `camel-ocsf`
   - `camel-ognl`
   - `camel-olingo2`
   - `camel-olingo2-api`
   - `camel-olingo2-parent`
   - `camel-olingo4`
   - `camel-olingo4-api`
   - `camel-olingo4-parent`
   - `camel-once`
   - `camel-openai`
   - `camel-openapi-java`
   - `camel-openapi-rest-dsl-generator`
   - `camel-openapi-validator`
   - `camel-opensearch`
   - `camel-openstack`
   - `camel-opentelemetry`
   - `camel-opentelemetry-metrics`
   - `camel-opentelemetry2`
   - `camel-optaplanner`
   - `camel-paho`
   - `camel-paho-mqtt5`
   - `camel-parquet-avro`
   - `camel-pdf`
   - `camel-pg-replication-slot`
   - `camel-pgevent`
   - `camel-pgvector`
   - `camel-pinecone`
   - `camel-platform-http`
   - `camel-platform-http-jolokia`
   - `camel-platform-http-main`
   - `camel-platform-http-vertx`
   - `camel-plc4x`
   - `camel-pqc`
   - `camel-printer`
   - `camel-protobuf`
   - `camel-pubnub`
   - `camel-pulsar`
   - `camel-python`
   - `camel-python3`
   - `camel-qdrant`
   - `camel-quartz`
   - `camel-quickfix`
   - `camel-quickjs`
   - `camel-reactive-streams`
   - `camel-reactor`
   - `camel-redis`
   - `camel-ref`
   - `camel-resilience4j`
   - `camel-resilience4j-micrometer`
   - `camel-resourceresolver-github`
   - `camel-rest`
   - `camel-rest-openapi`
   - `camel-rest-postman`
   - `camel-restdsl-openapi-plugin`
   - `camel-robotframework`
   - `camel-rocketmq`
   - `camel-rss`
   - `camel-rxjava`
   - `camel-saga`
   - `camel-salesforce`
   - `camel-salesforce-codegen`
   - `camel-salesforce-maven-plugin`
   - `camel-salesforce-parent`
   - `camel-sap-netweaver`
   - `camel-saxon`
   - `camel-scheduler`
   - `camel-schematron`
   - `camel-seda`
   - `camel-servicenow`
   - `camel-servicenow-maven-plugin`
   - `camel-servicenow-parent`
   - `camel-servlet`
   - `camel-shell`
   - `camel-shiro`
   - `camel-sjms`
   - `camel-sjms2`
   - `camel-slack`
   - `camel-smb`
   - `camel-smooks`
   - `camel-smpp`
   - `camel-snakeyaml`
   - `camel-snmp`
   - `camel-soap`
   - `camel-solr`
   - `camel-spiffe`
   - `camel-splunk-hec`
   - `camel-spring`
   - `camel-spring-ai-chat`
   - `camel-spring-ai-embeddings`
   - `camel-spring-ai-image`
   - `camel-spring-ai-parent`
   - `camel-spring-ai-vector-store`
   - `camel-spring-batch`
   - `camel-spring-cloud-config`
   - `camel-spring-jdbc`
   - `camel-spring-ldap`
   - `camel-spring-main`
   - `camel-spring-parent`
   - `camel-spring-rabbitmq`
   - `camel-spring-redis`
   - `camel-spring-security`
   - `camel-spring-ws`
   - `camel-spring-xml`
   - `camel-sql`
   - `camel-ssh`
   - `camel-state-store`
   - `camel-state-store-parent`
   - `camel-stax`
   - `camel-stitch`
   - `camel-stream`
   - `camel-streamcaching-test`
   - `camel-stringtemplate`
   - `camel-stripe`
   - `camel-stub`
   - `camel-support`
   - `camel-swift`
   - `camel-syslog`
   - `camel-tahu`
   - `camel-tarfile`
   - `camel-telegram`
   - `camel-telemetry`
   - `camel-telemetry-dev`
   - `camel-tensorflow-serving`
   - `camel-test-infra-all`
   - `camel-test-infra-artemis`
   - `camel-test-infra-cli`
   - `camel-test-infra-core`
   - `camel-test-infra-smb`
   - `camel-test-junit5`
   - `camel-test-junit6`
   - `camel-test-main-junit5`
   - `camel-test-main-junit6`
   - `camel-test-parent`
   - `camel-test-spring-junit5`
   - `camel-test-spring-junit6`
   - `camel-thrift`
   - `camel-thymeleaf`
   - `camel-tika`
   - `camel-timer`
   - `camel-tooling-maven`
   - `camel-toon`
   - `camel-tracing`
   - `camel-twilio`
   - `camel-twitter`
   - `camel-ubl`
   - `camel-undertow`
   - `camel-undertow-spring-security`
   - `camel-univocity-parsers`
   - `camel-validator`
   - `camel-velocity`
   - `camel-vertx`
   - `camel-vertx-common`
   - `camel-vertx-http`
   - `camel-vertx-parent`
   - `camel-vertx-websocket`
   - `camel-wal`
   - `camel-wasm`
   - `camel-weather`
   - `camel-weaviate`
   - `camel-web3j`
   - `camel-webhook`
   - `camel-whatsapp`
   - `camel-wordpress`
   - `camel-workday`
   - `camel-xchange`
   - `camel-xj`
   - `camel-xml-io`
   - `camel-xml-io-dsl`
   - `camel-xml-jaxb`
   - `camel-xml-jaxb-dsl`
   - `camel-xml-jaxb-dsl-test-definition`
   - `camel-xml-jaxb-dsl-test-spring`
   - `camel-xml-jaxp`
   - `camel-xmlsecurity`
   - `camel-xmpp`
   - `camel-xpath`
   - `camel-xslt`
   - `camel-xslt-saxon`
   - `camel-yaml-dsl-common`
   - `camel-yaml-dsl-validator`
   - `camel-yaml-dsl-validator-maven-plugin`
   - `camel-yaml-io`
   - `camel-zendesk`
   - `camel-zip-deflater`
   - `camel-zipfile`
   - `camel-zookeeper`
   - `camel-zookeeper-master`
   - `components`
   - `docs`
   
   </details>
   
   <details><summary>Modules with tests skipped (25)</summary>
   
   - `apache-camel`
   - `camel-allcomponents`
   - `camel-catalog-console`
   - `camel-catalog-maven`
   - `camel-catalog-suggest`
   - `camel-componentdsl`
   - `camel-endpointdsl`
   - `camel-endpointdsl-support`
   - `camel-itest`
   - `camel-jbang-core`
   - `camel-jbang-it`
   - `camel-jbang-main`
   - `camel-jbang-plugin-edit`
   - `camel-jbang-plugin-generate`
   - `camel-jbang-plugin-kubernetes`
   - `camel-jbang-plugin-test`
   - `camel-kamelet-main`
   - `camel-launcher`
   - `camel-report-maven-plugin`
   - `camel-route-parser`
   - `camel-yaml-dsl`
   - `camel-yaml-dsl-deserializers`
   - `camel-yaml-dsl-maven-plugin`
   - `coverage`
   - `dummy-component`
   
   </details>
   
   > :information_source: Shadow mode — Scalpel observes but does not affect test execution. [Learn more](https://github.com/maveniverse/scalpel)
   
   </details>
   
   :warning: **Some tests are disabled on GitHub Actions** (`@DisabledIfSystemProperty(named = "ci.env.name")`) and require manual verification:
   
   - `core/camel-core`: 2 test(s) disabled on GitHub Actions
   
   <details><summary>Build reactor — dependencies compiled but only changed modules were tested (6 modules)</summary>
   
   - Camel :: API
   - Camel :: Base
   - Camel :: Catalog :: Camel Catalog
   - Camel :: Console
   - Camel :: Core
   - Camel :: Docs
   
   </details>
   
   ---
   :gear: [View full build and test results](https://github.com/apache/camel/actions/runs/33673270331)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24377: Add JSON support to CamelEvent [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on PR #25495:
URL: https://github.com/apache/camel/pull/25495#issuecomment-5514388268

   @atiaomar1978-hub can you continue this work


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24377: Add JSON support to CamelEvent [camel]

Posted by "atiaomar1978-hub (via GitHub)" <gi...@apache.org>.
atiaomar1978-hub commented on PR #25495:
URL: https://github.com/apache/camel/pull/25495#issuecomment-5433741234

   ## CI fix — unresolved documentation xref
   
   Checked [CI run 31732539144](https://github.com/apache/camel/actions/runs/31732539144): **failure was from this PR**.
   
   ### Root cause
   `docs` module **xref-check** failed:
   ```
   Unresolved xrefs:
     manual:ROOT:event-notifier.adoc line 154:
     xref:components::others/backlog-tracer.adoc[Backlog Tracer]
   ```
   `backlog-tracer.adoc` lives in the user manual (`manual::`), not under `components::others`.
   
   ### Fix
   **Commit:** `d28e2f97633` — changed to `xref:backlog-tracer.adoc[Backlog Tracer]` (same pattern as `tracer.adoc`, `index.adoc`, etc.)
   
   ### Verification (local)
   ```bash
   ./mvnw -pl docs -Psourcecheck generate-resources -DskipTests   # xref-check: green
   ./mvnw -pl core/camel-core -am -Dtest=CamelEventJsonTest test  # green
   ```
   
   Pushed to `feature/CAMEL-24377-camel-event-json` — CI re-run should pass the docs xref-check step.
   
   ---
   _Composer on behalf of atiaomar1978-hub (AI-generated)_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24377: Add JSON support to CamelEvent [camel]

Posted by "atiaomar1978-hub (via GitHub)" <gi...@apache.org>.
atiaomar1978-hub commented on PR #25495:
URL: https://github.com/apache/camel/pull/25495#issuecomment-5284994176

   ## Bugbot / Grok self-review — findings addressed
   
   _AI-generated comment on behalf of atiaomar1978-hub (Cursor Agent)_
   
   ### Review summary
   
   | Severity | Finding | Status |
   |----------|---------|--------|
   | Medium | `ExchangeRedeliveryEvent` omitted exception in JSON | **Fixed** in `c916abe` — includes exchange exception |
   | Low | `appendException` lacked defensive try/catch | **Fixed** in `c916abe` — fallback to `exceptionMessage` |
   | Medium | Empty `docs/yarn.lock` in repo | **Not in this PR** — file is untracked locally, not committed |
   | High | Unrelated `scripts/post-pr-25433-inline-replies.sh` | **Not in this PR** — untracked locally, not committed |
   
   ### Test coverage (`CamelEventJsonTest`)
   
   - Context started event (`asJSon` + `toJSon`)
   - Exchange failed (via EventNotifier, exception fields)
   - Exchange sent (endpointUri, timeTaken)
   - Exchange failure handling (DLQ metadata)
   - Exchange redelivery (attempt + exception)
   - Route reloaded / restarting failure
   - Step failed
   - Service startup failure
   - JsonObject compatibility
   
   ### Tests
   
   ```bash
   ./mvnw -pl core/camel-core -am test -Dtest=CamelEventJsonTest -Dsurefire.failIfNoSpecifiedTests=false
   ```
   
   All 10 tests passing locally. Ready for human review.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24377: Add JSON support to CamelEvent [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #25495:
URL: https://github.com/apache/camel/pull/25495#issuecomment-5514770944

   <!-- regen-patch -->
   ### :warning: Generated files are out of date
   
   The [CI build](https://github.com/apache/camel/actions/runs/33667934676) regenerated files that are not committed on this PR.
   The missing changes are available as the `regen-patch` artifact of that run.
   
   Anyone with push access to this branch (the PR author, or a committer when
   *Allow edits from maintainers* is enabled) can apply and push them:
   
   ```bash
   gh pr checkout 25495 --repo apache/camel
   gh run download 33667934676 --repo apache/camel -n regen-patch
   git apply --index regen.patch && rm regen.patch pr-number
   git commit -m "Regen" && git push
   ```
   
   Alternatively, run `./etc/scripts/regen.sh` locally and commit the resulting changes.
   If the patch does not apply cleanly, update the branch from the base branch first —
   the patch was generated against the merge with the base branch.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24377: Add JSON support to CamelEvent [camel]

Posted by "atiaomar1978-hub (via GitHub)" <gi...@apache.org>.
atiaomar1978-hub commented on code in PR #25495:
URL: https://github.com/apache/camel/pull/25495#discussion_r3917862635


##########
core/camel-api/src/main/java/org/apache/camel/spi/CamelEvent.java:
##########
@@ -94,6 +96,22 @@ enum Type {
 
     void setTimestamp(long timestamp);
 
+    /**
+     * Dumps the full event as a pretty-printed JSON string.
+     *
+     * @param  indent number of spaces to indent
+     * @return        JSON representation of this event
+     * @since         4.23
+     */
+    String toJSon(int indent);
+
+    /**
+     * The full event as a {@link Map} suitable for JSON serialization, containing structured metadata for this event.
+     *
+     * @since 4.23
+     */
+    Map<String, Object> asJSon();

Review Comment:
   Fixed in **6c7b7bc** — both methods are now `default` with a minimal `type`/`timestamp`/`message` fallback using `LinkedHashMap` and `StringQuoteHelper` (no extra dependency on `camel-util-json` from `camel-api`). Built-in events continue to override via `CamelEventJsonSupport` for the rich structured JSON.
   
   Also added the upgrade guide entry in `camel-4x-upgrade-guide-4_23.adoc`.
   
   _Composer on behalf of atiaomar1978-hub (AI-generated)_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24377: Add JSON support to CamelEvent [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #25495:
URL: https://github.com/apache/camel/pull/25495#discussion_r3939941715


##########
core/camel-base/src/main/java/org/apache/camel/impl/event/CamelEventJsonSupport.java:
##########
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl.event;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePropertyKey;
+import org.apache.camel.Processor;
+import org.apache.camel.Route;
+import org.apache.camel.spi.CamelEvent;
+import org.apache.camel.support.MessageHelper;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.URISupport;
+import org.apache.camel.util.json.JsonObject;
+import org.apache.camel.util.json.Jsoner;
+
+/**
+ * Support class for serializing {@link CamelEvent} instances to JSON.
+ */
+public final class CamelEventJsonSupport {

Review Comment:
   Maybe we should add a note in the base event class an implementation not that this class should be updated in case we add new events.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24377: Add JSON support to CamelEvent [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus merged PR #25495:
URL: https://github.com/apache/camel/pull/25495


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24377: Add JSON support to CamelEvent [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #25495:
URL: https://github.com/apache/camel/pull/25495#discussion_r3921391287


##########
core/camel-api/src/main/java/org/apache/camel/spi/CamelEvent.java:
##########
@@ -94,6 +98,63 @@ enum Type {
 
     void setTimestamp(long timestamp);
 
+    /**
+     * Dumps the full event as a pretty-printed JSON string.
+     *
+     * @param  indent number of spaces to indent
+     * @return        JSON representation of this event
+     * @since         4.23
+     */
+    default String toJSon(int indent) {
+        Map<String, Object> map = asJSon();
+        String indentText = indent > 0 ? " ".repeat(indent) : "";
+        StringBuilder sb = new StringBuilder(128);
+        sb.append('{');
+        boolean first = true;
+        for (Map.Entry<String, Object> entry : map.entrySet()) {
+            if (!first) {
+                sb.append(',');
+            }
+            first = false;
+            if (indent > 0) {
+                sb.append('\n').append(indentText);
+            }
+            sb.append(StringQuoteHelper.doubleQuote(entry.getKey())).append(':');
+            if (indent > 0) {
+                sb.append(' ');
+            }
+            Object value = entry.getValue();
+            if (value instanceof Number || value instanceof Boolean) {
+                sb.append(value);
+            } else {
+                sb.append(StringQuoteHelper.doubleQuote(String.valueOf(value)));

Review Comment:
   `StringQuoteHelper.doubleQuote(...)` only wraps the value in `"` quotes — it does **not** JSON-escape `"`, `\`, or control characters. Because the default `asJSon()` sets `message` to `toString()` (which commonly contains endpoint URIs and exception text), this default `toJSon` produces invalid JSON whenever a value contains one of those characters.
   
   Example: a custom `CamelEvent` whose `toString()` is `He said "hi"` yields `{"message":"He said "hi""}` — broken JSON. The same applies to the key on line 122.
   
   Built-in events are unaffected (they override and delegate to `CamelEventJsonSupport` → `Jsoner`, which escapes), so this is confined to the default SPI path used by external implementers. Since `camel-api` doesn't depend on `camel-util-json`, a small manual escape of `"`, `\`, and control chars here (for both the key and the string value) would fix it without adding a dependency.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24377: Add JSON support to CamelEvent [camel]

Posted by "atiaomar1978-hub (via GitHub)" <gi...@apache.org>.
atiaomar1978-hub commented on PR #25495:
URL: https://github.com/apache/camel/pull/25495#issuecomment-5514403592

   Let me rebase @davsclaus 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org