question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

XmlMapper seems to ignore custom serializer

See original GitHub issue

I tried to add custom serializer to my XmlMapper for XML serialization:

JacksonXmlModule module = new JacksonXmlModule();
module.addSerializer(Item.class, new ItemSerializer());
XmlMapper xml = new XmlMapper(module);

However, it seems like XmlMapper ignore my serializer and serialize code on its own.

I tried this same serializer with ObjectMapper for JSON serialization:

SimpleModule module = new SimpleModule("MyModule", new Version(1,0,0,null,null,null);
module.addSerializer(Item.class, new ItemSerializer());
ObjectMapper json = new ObjectMapper();
json.registerModule(module);

It works fine for JSON.

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, Mar 12, 2015

@felixWackernagel There is unit test (TestSerializerCustom.java) that checks:

    public void testIssue42() throws Exception
    {
        XmlMapper xmlMapper = new XmlMapper();
        SimpleModule m = new SimpleModule("module", new Version(1,0,0,null,null,null));
        m.addSerializer(Item.class, new ItemSerializer());
        m.addDeserializer(Item.class, new ItemDeserializer());
        xmlMapper.registerModule(m);
        ....

so I would need more information on how your case differs.

But for issue tracking purposes, could you open a new issue? It is likely that underlying cause is different, and it is easier to create release notes when fixes are not spread across multiple releases (that is, fix for this problem was in 2.0.7; fix for remaining issue would go in 2.5.2)

0reactions
cowtowncodercommented, Jul 31, 2020

@kbansod I commented on #41 already, asking for reproduction. This will be needed for fix.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jackson xml ignore empty Objects when serializing
XmlMapper xmlMapper = new XmlMapper(); xmlMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);. I hope one of these helps, ten months late.
Read more >
Jackson Ignore Properties on Marshalling
This tutorial will show how to ignore certain fields when serializing an object to JSON using Jackson 2.x.
Read more >
Solving the XML Problem with Jackson
The XmlMapper is able to serialize an entire Java bean into a document that is currently being produced, allowing Jackson to integrate and ......
Read more >
FasterXML/jackson-databind - Gitter
XmlMapper will create DeserializationContext to use (either itself or by ... Here is my custom serializer, i'm trying to implement this functionality, ...
Read more >
Solving the XML Problem with Jackson
Jackson is a popular library for handling JSON in Java ... The XmlMapper is able to serialize an entire Java bean into a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found