Skip to content

Serialize Character values in XContent maps - #22814

Open
kalayciburak wants to merge 1 commit into
opensearch-project:mainfrom
kalayciburak:fix/xcontent-character-writer
Open

Serialize Character values in XContent maps#22814
kalayciburak wants to merge 1 commit into
opensearch-project:mainfrom
kalayciburak:fix/xcontent-character-writer

Conversation

@kalayciburak

Copy link
Copy Markdown

Description

XContentBuilder rejected Character values with cannot write xcontent for unknown value of type class java.lang.Character. Ingest scripts such as ctx.char = (char)'a' put a Character into the document map, and IngestService then failed while serializing that map.

Register Character in the WRITERS table and write it as a one-character string, matching Locale / Class.

Related Issues

Resolves #14382

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

Test plan

Executed as a non-root user on JDK 21:

  • RED: :server:test --tests org.opensearch.common.xcontent.builder.XContentBuilderTests.testWriteMapWithCharacterValue failed with IllegalArgumentException: cannot write xcontent for unknown value of type class java.lang.Character
  • GREEN: the same test plus JsonXContentTests.testUnknownObject
  • :server:test --tests org.opensearch.common.xcontent.builder.XContentBuilderTests --tests org.opensearch.common.xcontent.json.JsonXContentTests --tests org.opensearch.common.xcontent.smile.SmileXContentTests.testUnknownObject --tests org.opensearch.common.xcontent.cbor.CborXContentTests.testUnknownObject --tests org.opensearch.common.xcontent.yaml.YamlXContentTests.testUnknownObject
  • spotlessJavaCheck

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

ScriptProcessor can put Character values into the ingest
document map. XContentBuilder rejected them because
Character was missing from the WRITERS registry.

Fixes opensearch-project#14382

Signed-off-by: Burak KALAYCI <kalayciburak1996@gmail.com>
@kalayciburak
kalayciburak requested a review from a team as a code owner August 23, 2026 11:56
@github-actions github-actions Bot added bug Something isn't working Indexing Indexing, Bulk Indexing and anything related to indexing labels Aug 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ No major issues detected

@github-actions

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Also handle primitive char array type

Also register a writer for char[] so primitive character arrays are serialized
consistently with other primitive array types (e.g., int[], short[]). Without this,
a char[] value in a map would fall through to a generic handler or fail.

libs/core/src/main/java/org/opensearch/core/xcontent/XContentBuilder.java [121]

 writers.put(Character.class, (b, v) -> b.value(v.toString()));
+writers.put(char[].class, (b, v) -> b.value(new String((char[]) v)));
Suggestion importance[1-10]: 5

__

Why: Adding a char[] writer for consistency with other primitive array types is reasonable, though the PR's scope is narrowly focused on Character handling. The suggestion is a valid enhancement but not critical, and serialization as a String may not be the desired behavior (vs. an array of chars).

Low

@github-actions

Copy link
Copy Markdown
Contributor

❌ Gradle check result for 5975d68: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@iprithv iprithv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

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

Labels

bug Something isn't working Indexing Indexing, Bulk Indexing and anything related to indexing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] ScriptProcessor fails with char data type

2 participants