Skip to content

Include free-form message when encoding StructuredDataMessage to XML#4180

Merged
ramanathan1504 merged 4 commits into
apache:2.xfrom
kamilkrzywanski:fix/4141-structured-data-message-xml
Jul 18, 2026
Merged

Include free-form message when encoding StructuredDataMessage to XML#4180
ramanathan1504 merged 4 commits into
apache:2.xfrom
kamilkrzywanski:fix/4141-structured-data-message-xml

Conversation

@kamilkrzywanski

Copy link
Copy Markdown
Contributor

What

Fixes #4141: StructuredDataMessage XML encoding omitted the free-form message supplied at construction.

Changes

  • Encode the constructor message field as a distinct <message> element in asXml, with the same XML escaping used for type and id
  • Keep it separate from map entries so a user-supplied put("message", ...) remains an independent SD-PARAM
  • Omit the element when the constructor message is null
  • Add regression tests for inclusion, escaping, and the map-key conflict case

Example

new StructuredDataMessage("an id", "a message", "a type");

now encodes as:

<StructuredData>
<type>a type</type>
<id>an id</id>
<message>a message</message>
<Map>
</Map>
</StructuredData>

When both the constructor message and a map entry keyed "message" are set, both appear:

<message>a message</message>
...
  <Entry key="message">foo</Entry>

Testing

mvn -pl log4j-api-test -am test -Dtest=StructuredDataMessageTest -Dsurefire.failIfNoSpecifiedTests=false

All StructuredDataMessageTest cases pass.

StructuredDataMessage.asXml omitted the constructor message field. Encode
it as a distinct <message> element so it is not conflated with a map entry
keyed "message". Fixes apache#4141.
@ramanathan1504

Copy link
Copy Markdown
Contributor

@kamilkrzywanski Thanks for the Pr. Give some time i will review this ASAP

@ramanathan1504

Copy link
Copy Markdown
Contributor

@kamilkrzywanski

Tests look great and passed locally.
I noticed the Spotless formatting check failed, so I just pushed a quick commit to your branch to apply the formatting. For future PRs, just make sure to check out the BUILDING.adoc before committing so you can run the Spotless checks locally.

LGTM 👍🏾

@ramanathan1504
ramanathan1504 enabled auto-merge (squash) July 18, 2026 07:23
@ramanathan1504
ramanathan1504 merged commit 38889a8 into apache:2.x Jul 18, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from Approved to Merged in Log4j pull request tracker Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

Serializing StructuredDataMessage to XML omits the message field

2 participants