Skip to content

XML module not registered correctly when setting a custom SerializerFactory #678

@SimonCockx

Description

@SimonCockx

I'm using a custom SerializerFactory as follows.

ObjectMapper mapper = new XmlMapper().setSerializerFactory(MySerializerFactory.INSTANCE);

I noticed that in the constructor of XmlMapper, the default XML_MODULE is registered, which also configures the SerializerFactory. Since I'm overriding it after constructing, this configuration is lost, resulting in different behaviour, which is very confusing.

I currently don't see any way for registering my custom SerializerFactory before the XML_MODULE is registered. Is this intended? It seems error-prone.

My current workaround:

ObjectMapper mapper = new XmlMapper((JacksonXmlModule) null)
    .setSerializerFactory(RosettaSerialiserFactory.INSTANCE)
    .registerModule(new JacksonXmlModule());

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.18Issues planned at earliest for 2.18

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions