Skip to content

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

Open
kamilkrzywanski wants to merge 1 commit into
apache:2.xfrom
kamilkrzywanski:fix/4141-structured-data-message-xml
Open

Include free-form message when encoding StructuredDataMessage to XML#4180
kamilkrzywanski wants to merge 1 commit into
apache:2.xfrom
kamilkrzywanski:fix/4141-structured-data-message-xml

Conversation

@kamilkrzywanski

Copy link
Copy Markdown

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.
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

1 participant