Skip to content

[Bug]: JacksonXmlOps does not validate single root element requirement #159

@Splatcrafter

Description

@Splatcrafter

AI REVIEWED

Module: codec
File: codec/xml/jackson/JacksonXmlOps.java (~line 137-150)
Severity: Medium

Summary

XML requires exactly one root element, but createMap() allows constructing maps with multiple top-level entries. Serialization to XML only fails at write time — no fail-fast at the DynamicOps level.

Expected Behavior

Either validate the single root constraint in relevant operations, or document that users must ensure single-root structure before XML serialization.

Actual Behavior

Multiple root-level entries are silently accepted. XML serialization fails with a confusing Jackson error instead of a clear Aether error.

Suggested Fix

Add documentation and optionally a validateForSerialization() helper:

/**
 * Validates that the given node is suitable for XML serialization.
 * @throws IllegalArgumentException if the structure has multiple root elements
 */
public void validateForSerialization(JsonNode node) { ... }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions