CAMEL-24620: Add support to enable/disable features from DatatypeFeature enums - #26103
CAMEL-24620: Add support to enable/disable features from DatatypeFeature enums#26103graben wants to merge 1 commit into
Conversation
davsclaus
left a comment
There was a problem hiding this comment.
data formats are special and options must be defined in the model so its confirgurable via the DSLs
|
@davsclaus : I can't see a corresponding model class that would be affected? |
davsclaus
left a comment
There was a problem hiding this comment.
Seconding the existing CHANGES_REQUESTED review — the core issue is that every data format option must be configured via the model, and this PR bypasses that contract.
Specifically:
-
enableFeature(Enum<? extends DatatypeFeature>)/disableFeature(Enum<? extends DatatypeFeature>)are Java-only convenience methods. They are not exposed inJsonDataFormat(incore/camel-core-model), so there is no way to configureDateTimeFeature,EnumFeature, orJsonNodeFeaturethrough the YAML/XML DSLs or from the component endpoint URI. Data formats in Camel must be configurable solely through the model — if it isn't in the model, it effectively doesn't exist for most users. -
The generic
Enum<? extends DatatypeFeature>parameter type is also inconsistent with the existing overloads (enableFeature(SerializationFeature),enableFeature(DeserializationFeature),enableFeature(MapperFeature)) which all use concrete enum types.
Required changes:
- Update
JsonDataFormatincore/camel-core-modelto expose the new feature types (ideally as dedicatedenableDateTimeFeatures,enableEnumFeatures,enableJsonNodeFeaturesString properties — similar to howenableFeatureshandlesSerializationFeature/DeserializationFeature/MapperFeature) - Wire those model properties through the configurer so they reach
AbstractJacksonDataFormatat runtime - The
doEnableFeatures()/doDisableFeatures()extension to resolve the new enum names (the bulk of the diff) is a good foundation — just needs to be driven from model-level properties
Also a minor test issue:
|
|
||
| template.send("direct:unformat", exchange -> exchange.getIn().setBody(new Date(123))); | ||
|
|
||
| mock.expectedMessageCount(1); |
There was a problem hiding this comment.
expectedMessageCount should be set before template.send(), not after. As written, the message can arrive and be recorded before the latch is initialised, making the assertion non-deterministic.
| mock.expectedMessageCount(1); | |
| mock.expectedMessageCount(1); | |
| mock.message(0).body().isEqualTo("123"); | |
| template.send("direct:unformat", exchange -> exchange.getIn().setBody(new Date(123))); | |
|
To clarify the model requirement from the previous review: The new feature types ( Since these are Jackson 3 specific (these DatatypeFeature subtypes don't exist in Jackson 2 or other JSON libraries), any shared model that also covers other JSON data formats would need The Claude Code on behalf of davsclaus |
|
Well, I see those new methods as convient methods for Jackson only. They are implemented like the three original methods which aren't reflected by model class, too, because they are not generic. The test method might be problematic, like all test cases in that class! But I can fix them all. :-) I think the most common way to configure this json dataformat is using the String method disable/enableFeatures which is only enhanced by this PR. So no need for a model change. It's up to you if I should change also legacy code to make it complete. |
|
You're right — no model change is needed. The existing Here is what I'd like to see added to the test to demonstrate that the model path works end-to-end (this is the style that YAML/XML DSL users will rely on): @Test
public void testEnableDatatypeFeatureViaModelString() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result-model");
mock.expectedMessageCount(1);
mock.message(0).body().isEqualTo("123");
template.send("direct:unformat-model", exchange -> exchange.getIn().setBody(new Date(123)));
mock.assertIsSatisfied();
}With a corresponding route using JacksonDataFormat formatModel = new JacksonDataFormat();
formatModel.setEnableFeatures("WRITE_DATES_AS_TIMESTAMPS");
from("direct:unformat-model").marshal(formatModel).to("mock:result-model");Also please fix the mock ordering in the existing and new tests — // Correct ordering:
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
mock.message(0).body().isEqualTo("123");
template.send(...);
mock.assertIsSatisfied();Also please update the Javadoc on Claude Code on behalf of davsclaus |
No description provided.