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

   # Description
   
   Bindy currently aborts the entire unmarshal operation if any field on any 
row fails to parse — a single malformed date or non-numeric integer brings down 
the whole batch, even when the rest of the row would have parsed fine. There is 
no per-field recovery path and no way to substitute a fallback value short of 
pre-cleaning the input upstream.
   
   This PR adds an opt-in tolerance mode driven by two new annotation elements: 
`continueParseOnFailure` on `@CsvRecord` / `@FixedLengthRecord` / `@Message` 
(record-level `boolean`, default `false`) and `continueParseOnFailure` on 
`@DataField` / `@KeyValuePairField` (field-level tri-state 
`ResumeUnmarshalingState`, default `INHERIT`). The field-level value can 
override the record-level default per field, with `INHERIT` deferring to the 
record. All defaults preserve today's strict behaviour.
   
   When a field is tolerant and parsing fails, Bindy substitutes the field's 
existing `@DataField.defaultValue` (parsed through the same `Format` instance 
that just failed, so the substitute is automatically the right Java type). If 
no `defaultValue` is set the field gets the same fallback an unfilled field 
would get today: `null` for object types, `""` for `String`, `false` for 
`boolean`, and `MIN_VALUE` for numeric primitives — the existing 
`getDefaultValueForPrimitive` convention. `@KeyValuePairField` does not have a 
`defaultValue` element today, so KVP fields can only fall back to the 
type-appropriate default.
   
   A pluggable `ParserErrorHandler` interface (similar to FHIR's 
`IParserErrorHandler`) was discussed and intentionally deferred to keep this PR 
small and the public surface minimal. A callback layer can be added later as a 
non-breaking addition if real demand emerges.
   
   Override semantics:
   
   | `@CsvRecord` | `@DataField` | Effective behavior |
   |---|---|---|
   | (unset / `false`) | `INHERIT` | Strict — exception propagates (today's 
behavior) |
   | `true` | `INHERIT` | Tolerant |
   | `true` | `FALSE` | Strict (field wins) |
   | `false` | `TRUE` | Tolerant (field wins) |
   
   ## Changes
   
   - New enum `ResumeUnmarshalingState { INHERIT, TRUE, FALSE }` introduced for 
the field-level tri-state.
   - `continueParseOnFailure()` element added to `@CsvRecord`, 
`@FixedLengthRecord`, `@Message` (record-level `boolean`).
   - `continueParseOnFailure()` element added to `@DataField` and 
`@KeyValuePairField` (field-level `ResumeUnmarshalingState`).
   - `BindyAbstractFactory` gains `shouldContinueOnFailure(...)` for tri-state 
resolution and `parseField(...)` for the shared parse-with-fallback path. Both 
factories and the KVP `formatField` route through it.
   - `BindyCsvFactory.initCsvRecordParameters`, 
`BindyFixedLengthFactory.initFixedLengthRecordParameters`, and 
`BindyKeyValuePairFactory.initMessageParameters` now read the record-level flag 
and store it on the factory instance.
   - New test classes `BindyCsvContinueOnParseFailureTest`, 
`BindyFixedContinueOnParseFailureTest`, `BindyKvpContinueOnParseFailureTest` 
covering the 6-row override matrix per factory, plus value-fallback variants: 
`defaultValue` substitution, strict mode ignoring `defaultValue`, malformed 
`defaultValue` propagating, primitive `int` field → `Integer.MIN_VALUE`, 
multi-bad-field row with per-field fallbacks, and a regression check for valid 
input on a tolerant record.
   - New "Handling parse failures" section in `bindy-dataformat.adoc` covering 
the feature, override matrix, substitution rules, and the `MIN_VALUE` primitive 
convention.
   - Upgrade-guide entry added to `camel-4x-upgrade-guide-4_21.adoc`.
   
   # 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-17598) 
filed for the change.
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [x] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
   
   ---
   
   _Claude Code on behalf of Vishal Nagaraj_


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to