You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "allthingssecurity (via GitHub)" <gi...@apache.org> on 2026/10/17 00:12:10 UTC

[PR] CAMEL-25703: camel-bindy - keep all decimals of a number field without precision when marshalling [camel]

allthingssecurity opened a new pull request, #27988:
URL: https://github.com/apache/camel/pull/27988

   # Description
   
   [CAMEL-25703](https://issues.apache.org/jira/browse/CAMEL-25703)
   
   Since CAMEL-24168 the default `precision` of `@DataField` / `@KeyValuePairField` is `-1`, "to preserve the original scale from the input". Unmarshal keeps it, but marshal still rounds: for an unset precision `AbstractNumberFormat` leaves the `new DecimalFormat()` with its default pattern `#,##0.###`, which keeps at most three fraction digits (`HALF_EVEN`). So a `BigDecimal`, `Double` or `Float` field without `precision` and `pattern` is written with at most three decimals, silently:
   
   | field | value | written before this change |
   |---|---|---|
   | `BigDecimal` | `1.23456` | `1.235` |
   | `Double` | `12.3456789` | `12.346` |
   | `Double` | `0.000123` | `0` |
   
   A record that is unmarshalled and marshalled again therefore changes its numbers (CSV, fixed-length and key-value pair records all use these formats). The test added by CAMEL-24168 uses `10.35`, which has only two decimals.
   
   Change:
   - `AbstractNumberFormat`: without a precision (and without an implied decimal separator) the formatter keeps all fraction digits (`setMaximumFractionDigits(Integer.MAX_VALUE)`; `DecimalFormat` limits a `double` to 340 itself and prints its shortest decimal form). Whole numbers are still written without decimals (`10`), grouping and locale symbols are unchanged.
   - `FloatFormatFactory`: a finite `Float` with a fraction part and without precision is formatted from `Float.toString`, so `1.1f` stays `1.1` and does not become `1.100000023841858` through the widening to `double`. A whole-number `Float` keeps its exact digits as before (`123456792`, not the shorter `123456790` of `Float.toString`).
   - An explicit `precision`, a `pattern` or `impliedDecimalSeparator` work as before.
   
   What users can notice: such values are now written with all their decimals, also a `Double` that is the result of a calculation (`0.1 + 0.2` is written `0.30000000000000004`, before `0.3`). A note is added to the 4.24 upgrade guide; users who want a fixed number of decimals set `precision`.
   
   Tests:
   - New `BindyNumberWithoutPrecisionKeepsDecimalsTest` (5 tests, locale `en`): CSV marshal of `1.23456`, `0.000123`, `1.1f`; CSV unmarshal then marshal of `0.98765,12.3456789,2.5`; a fixed-length record unmarshalled and marshalled again; and two controls: `10`, `10.0` and `0.5f` are written as `10,10,0.5`, and the whole-number float `123456792f` as `123456792`.
   - Without the change (first four tests): 4 run, 3 failures (`but was: <1.235,0,1.1`, `<0.988,12.346,2.5`, `<     1.235         0`); the first control passes. The whole-number float control was added later and not run against main; main writes that float through the same `double` path, so it pins unchanged output.
   - With the change the camel-bindy tests pass: 243 run, 0 failures, 0 errors, 3 skipped (238 existing and the 5 new ones; the 3 skips are existing tests that were skipped before).
   
   What is not changed: the pattern formats (`DecimalFormat.parse` accepts a valid prefix of the text, a separate question), the `Integer` / `Long` formats, and the output of trailing zeros (`10.50` is written `10.5`, as before).
   
   What was not run: the full root build.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it): [CAMEL-25703](https://issues.apache.org/jira/browse/CAMEL-25703).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful subject line and body.
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes.
     (I built and tested camel-bindy, including the formatter and import-sort plugins. I did not run the full root build.)
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used.
     This PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer.
   
   _Claude Code on behalf of allthingssecurity_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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-25703: camel-bindy - keep all decimals of a number field without precision when marshalling [camel]

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

   :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-25703: camel-bindy - keep all decimals of a number field without precision when marshalling [camel]

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

   <!-- ci-tested-modules -->
   :test_tube: **CI tested the following changed modules:**
   
   - `components/camel-bindy`
   - `docs`
   
   ---
   
   <details><summary>:microscope: Scalpel shadow comparison — Scalpel: 8 of 706 tested, 26 compile-only — current: 8 all tested</summary>
   
   [Maveniverse Scalpel](https://github.com/maveniverse/scalpel) detected **8 affected modules** (current approach: 8).
   
   **Skip-tests mode would test 8 modules** (2 direct + 7 downstream), **skip tests for 26** (generated code, meta-modules)
   
   <details><summary>Modules Scalpel would test (8)</summary>
   
   - `camel-bindy` ← components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/AbstractNumberFormat.java, components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/FloatFormatFactory.java, components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyNumberWithoutPrecisionKeepsDecimalsTest.java
   - `camel-jbang-mcp` ← downstream of org.apache.camel:camel-catalog
   - `camel-jbang-plugin-mcp` ← downstream of org.apache.camel:camel-jbang-core
   - `camel-jbang-plugin-tui` ← downstream of org.apache.camel:camel-catalog
   - `camel-jbang-plugin-validate` ← downstream of org.apache.camel:camel-yaml-dsl-validator
   - `camel-launcher-container` ← downstream of org.apache.camel:camel-launcher
   - `camel-yaml-dsl-validator` ← downstream of org.apache.camel:camel-catalog
   - `camel-yaml-dsl-validator-maven-plugin` ← downstream of org.apache.camel:camel-yaml-dsl-validator
   
   </details>
   
   <details><summary>Modules with tests skipped (26)</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`
   - `dummy-component`
   
   </details>
   
   > :information_source: Shadow mode — Scalpel observes but does not affect test execution. [Learn more](https://github.com/maveniverse/scalpel)
   
   </details>
   
   <details><summary>All tested modules (35 modules, 5m 10s total)</summary>
   
   **Total reactor time:** 5m 10s
   
   | Module | Duration | Status |
   | --- | --- | --- |
   | Camel :: Launcher | 46.1s | SUCCESS |
   | Camel :: JBang :: MCP | 38.4s | SUCCESS |
   | Camel :: JBang :: Plugin :: Validate | 35.0s | SUCCESS |
   | Camel :: Bindy | 25.4s | SUCCESS |
   | Camel :: Catalog :: Camel Catalog | 21.2s | SUCCESS |
   | Camel :: YAML DSL :: Validator | 19.9s | SUCCESS |
   | Camel :: YAML DSL | 17.4s | SUCCESS |
   | Camel :: Component DSL | 16.2s | SUCCESS |
   | Camel :: Docs | 11.9s | SUCCESS |
   | Camel :: Kamelet Main | 11.2s | SUCCESS |
   | Camel :: JBang :: Plugin :: Kubernetes | 11.1s | SUCCESS |
   | Camel :: YAML DSL :: Deserializers | 7.8s | SUCCESS |
   | Camel :: Catalog :: Camel Route Parser | 6.8s | SUCCESS |
   | Camel :: Catalog :: Camel Report Maven Plugin | 6.3s | SUCCESS |
   | Camel :: JBang :: Plugin :: Testing | 6.1s | SUCCESS |
   | Camel :: YAML DSL :: Validator Maven Plugin | 6.0s | SUCCESS |
   | Camel :: All Components Sync point | 5.0s | SUCCESS |
   | Camel :: YAML DSL :: Maven Plugins | 2.8s | SUCCESS |
   | Camel :: Catalog :: Maven | 2.4s | SUCCESS |
   | Camel :: Catalog :: Suggest (deprecated) | 2.1s | SUCCESS |
   | Camel :: JBang :: Plugin :: Edit | 1.9s | SUCCESS |
   | Camel :: Assembly | 1.7s | SUCCESS |
   | Camel :: Coverage | 1.3s | SUCCESS |
   | Camel :: Catalog :: Dummy Component | 1.1s | SUCCESS |
   | Camel :: JBang :: Integration tests | 1.0s | SUCCESS |
   | Camel :: JBang :: Plugin :: Generate | 1.0s | SUCCESS |
   | Camel :: Catalog :: Console | 0.8s | SUCCESS |
   | Camel :: Endpoint DSL :: Support | 0.8s | SUCCESS |
   | Camel :: JBang :: Main | 0.7s | SUCCESS |
   | Camel :: Launcher :: Container | 0.6s | SUCCESS |
   | Camel :: JBang :: Plugin :: MCP | 0.6s | SUCCESS |
   | Camel :: Endpoint DSL | n/a |  |
   | Camel :: Integration Tests | n/a |  |
   | Camel :: JBang :: Core | n/a |  |
   | Camel :: JBang :: Plugin :: TUI | n/a |  |
   
   **Top 20 slowest modules:**
   - `Camel :: Launcher` (46.1s)
   - `Camel :: JBang :: MCP` (38.4s)
   - `Camel :: JBang :: Plugin :: Validate` (35.0s)
   - `Camel :: Bindy` (25.4s)
   - `Camel :: Catalog :: Camel Catalog` (21.2s)
   - `Camel :: YAML DSL :: Validator` (19.9s)
   - `Camel :: YAML DSL` (17.4s)
   - `Camel :: Component DSL` (16.2s)
   - `Camel :: Docs` (11.9s)
   - `Camel :: Kamelet Main` (11.2s)
   - `Camel :: JBang :: Plugin :: Kubernetes` (11.1s)
   - `Camel :: YAML DSL :: Deserializers` (7.8s)
   - `Camel :: Catalog :: Camel Route Parser` (6.8s)
   - `Camel :: Catalog :: Camel Report Maven Plugin` (6.3s)
   - `Camel :: JBang :: Plugin :: Testing` (6.1s)
   - `Camel :: YAML DSL :: Validator Maven Plugin` (6.0s)
   - `Camel :: All Components Sync point` (5.0s)
   - `Camel :: YAML DSL :: Maven Plugins` (2.8s)
   - `Camel :: Catalog :: Maven` (2.4s)
   - `Camel :: Catalog :: Suggest (deprecated)` (2.1s)
   
   </details>
   
   ---
   :gear: [View full build and test results](https://github.com/apache/camel/actions/runs/38987047703)


-- 
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-25703: camel-bindy - keep all decimals of a number field without precision when marshalling [camel]

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


##########
docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc:
##########
@@ -521,6 +521,14 @@ now resolves to no value, as it already did without a field, so its default valu
 (`{{?hashicorp:secret:missing#field}}`) applies. Before, without a default value, it failed with a
 `NullPointerException`.
 
+=== camel-bindy - a number field without precision keeps all its decimals when marshalled
+
+A `BigDecimal`, `Double` or `Float` field whose `@DataField` (or `@KeyValuePairField`) has no `precision` and no
+`pattern` was marshalled with at most three decimals, rounded: `1.23456` was written as `1.235` and `0.000123` as `0`.

Review Comment:
   Good point, thanks. Fixed in a7dac494ce24. I checked the 4.21.0 sources: `@DataField` and `@KeyValuePairField` had `precision() default 0`, and `AbstractNumberFormat` then set both minimum and maximum fraction digits to 0. The sentence now reads: "...was marshalled with at most three decimals, rounded: `1.23456` was written as `1.235` and `0.000123` as `0` (since Camel 4.22, CAMEL-24168; up to Camel 4.21 the default `precision = 0` wrote these fields without any decimals)."
   
   _Claude Code on behalf of allthingssecurity_
   



-- 
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-25703: camel-bindy - keep all decimals of a number field without precision when marshalling [camel]

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


-- 
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-25703: camel-bindy - keep all decimals of a number field without precision when marshalling [camel]

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


##########
docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc:
##########
@@ -521,6 +521,14 @@ now resolves to no value, as it already did without a field, so its default valu
 (`{{?hashicorp:secret:missing#field}}`) applies. Before, without a default value, it failed with a
 `NullPointerException`.
 
+=== camel-bindy - a number field without precision keeps all its decimals when marshalled
+
+A `BigDecimal`, `Double` or `Float` field whose `@DataField` (or `@KeyValuePairField`) has no `precision` and no
+`pattern` was marshalled with at most three decimals, rounded: `1.23456` was written as `1.235` and `0.000123` as `0`.

Review Comment:
   Nit: "at most three decimals" only holds since 4.22 (CAMEL-24168). Up to 4.21, the default `precision = 0` wrote these fields without any decimals. The 4.22 guide only mentions `BigDecimal`, so the `Double`/`Float` change in 4.22 was never documented. Readers upgrading from 4.18 LTS could use a short clause here, for example "(since Camel 4.22; before that, without any decimals)".



-- 
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-25703: camel-bindy - keep all decimals of a number field without precision when marshalling [camel]

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


##########
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyNumberWithoutPrecisionKeepsDecimalsTest.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.dataformat.bindy.csv;
+
+import java.math.BigDecimal;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
+import org.apache.camel.dataformat.bindy.annotation.DataField;
+import org.apache.camel.dataformat.bindy.annotation.FixedLengthRecord;
+import org.apache.camel.model.dataformat.BindyDataFormat;
+import org.apache.camel.model.dataformat.BindyType;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * A BigDecimal, Double or Float field without a precision keeps all its decimals when it is marshalled, so that a
+ * record unmarshalled and marshalled again is the same text. The default formatter of the JDK keeps at most three
+ * decimals.
+ */
+public class BindyNumberWithoutPrecisionKeepsDecimalsTest extends CamelTestSupport {
+
+    @Test
+    public void csvMarshalKeepsAllDecimals() {
+        CsvModel model = new CsvModel();
+        model.rate = new BigDecimal("1.23456");
+        model.ratio = 0.000123d;
+        model.weight = 1.1f;

Review Comment:
   💡 **Suggestion:** Consider also testing a float that produces scientific notation in `Float.toString()` (e.g. `0.000123f` → `"1.23E-4"`). This would explicitly verify that `new BigDecimal(Float.toString(0.000123f))` round-trips correctly through the marshaller and produces `"1.23E-4"` or `"0.000123"` as expected.



-- 
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-25703: camel-bindy - keep all decimals of a number field without precision when marshalling [camel]

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


##########
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyNumberWithoutPrecisionKeepsDecimalsTest.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.dataformat.bindy.csv;
+
+import java.math.BigDecimal;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
+import org.apache.camel.dataformat.bindy.annotation.DataField;
+import org.apache.camel.dataformat.bindy.annotation.FixedLengthRecord;
+import org.apache.camel.model.dataformat.BindyDataFormat;
+import org.apache.camel.model.dataformat.BindyType;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * A BigDecimal, Double or Float field without a precision keeps all its decimals when it is marshalled, so that a
+ * record unmarshalled and marshalled again is the same text. The default formatter of the JDK keeps at most three
+ * decimals.
+ */
+public class BindyNumberWithoutPrecisionKeepsDecimalsTest extends CamelTestSupport {
+
+    @Test
+    public void csvMarshalKeepsAllDecimals() {
+        CsvModel model = new CsvModel();
+        model.rate = new BigDecimal("1.23456");
+        model.ratio = 0.000123d;
+        model.weight = 1.1f;

Review Comment:
   Thanks, both added in 42ab0b162717:
   
   - `floatWithScientificToStringIsWrittenInPlainDecimals`: `0.000123f` (`Float.toString` gives `1.23E-4`) is written as `0.000123`.
   - `keyValuePairRecordIsTheSameAfterUnmarshalAndMarshal`: a `@KeyValuePairField` record `1=1.23456 2=0.000123 3=1.1` (BigDecimal, Double, Float) is unmarshalled and marshalled back to the same text.
   
   camel-bindy tests: 245 run, 0 failures, 0 errors, 3 skipped.
   
   _Claude Code on behalf of allthingssecurity_



-- 
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