Skip to content

Bad map keys can not be unmarshaled #523

Closed
@mensinda

Description

@mensinda

Specifically map keys like 000 and 111 will be marshaled as <000> and <111>, which can no longer be unmarshaled. Jackson should make sure to escape those keys correctly.

Example:

package it;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;

import java.util.Map;

public class BadMap {
    public static class DTO {
        public Map<String, String> badMap = Map.of("000", "foo", "111", "bar");
    }

    public static void main(String ... args) throws JsonProcessingException {
        DTO dto = new DTO();

        XmlMapper mapper = new XmlMapper();

        final String res = mapper.writeValueAsString(dto);

        // <DTO><badMap><000>foo</000><111>bar</111></badMap></DTO>
        System.out.println(res);

        // ERROR!
        // com.fasterxml.jackson.core.JsonParseException: Unexpected character '0' (code 48) in content after '<' (malformed start element?).
        mapper.readValue(res, DTO.class);
    }
}

jackson version: 2.13.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions