Skip to content

Accept empty string as null in PluginModel deserializer and add Coerc…#6915

Open
Davidding4718 wants to merge 3 commits into
opensearch-project:mainfrom
Davidding4718:main
Open

Accept empty string as null in PluginModel deserializer and add Coerc…#6915
Davidding4718 wants to merge 3 commits into
opensearch-project:mainfrom
Davidding4718:main

Conversation

@Davidding4718

Copy link
Copy Markdown
Contributor

Description

After Jackson-dataformat-yaml 2.13+, bare YAML keys (e.g., stdout:, newline:) produce VALUE_STRING "" instead of VALUE_NULL. This change updates PluginModel to:

  1. Accept empty string as null at the PluginModel deserializer level — bare plugin keys like stdout: are treated as plugins with null settings (same behavior as Jackson 2.12)
  2. Add CoercionConfig on SERIALIZER_OBJECT_MAPPER — configures EmptyString → AsNull so that when plugin settings are converted to typed model classes via convertValue(), empty strings from bare YAML keys are coerced to null

This maintains backward compatibility for pipeline configurations that use bare keys for plugins with no settings, which is the standard YAML pattern for Data Prepper pipelines.

Issues Resolved

Resolves #6598 (follow-up — original PR rejected empty strings; this accepts them per team decision)

Check List

  • New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

…ionConfig for settings conversion

Signed-off-by: Siqi Ding <dingdd@amazon.com>
private static final ObjectMapper SERIALIZER_OBJECT_MAPPER = new ObjectMapper();
static {
SERIALIZER_OBJECT_MAPPER.coercionConfigDefaults()
.setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsNull);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is the right solution. It is going to affect all strings making them the same as null.

I think we should avoid this coercion.

In the plugin framework we handle the situation where the plugin is provided as:

something_using_a_plugin:
  some_plugin: ""

Only when parsing the PluginModel should you treat an empty string ("") the same as null.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. The global CoercionConfig was too broad and would silently null out legitimate empty strings in plugin settings. I have removed it in the newest commit.

Remove the SERIALIZER_OBJECT_MAPPER CoercionConfig that globally coerced
empty strings to null across all fields. The targeted VALUE_STRING check
in the deserializer already handles bare YAML keys (e.g. stdout:) by
treating empty string as null only at the plugin name level.

Signed-off-by: Siqi Ding <dingdd@amazon.com>

@dlvenable dlvenable left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Davidding4718 for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants