On Thu, Sep 27, 2018 at 10:29 PM Tristan Lins <[email protected]>
wrote:

> I need to serialize / deserialize a Map<String, Object> to / from XML with
> dataformat-xml / XmlMapper.
>
> It works fine with JSON when using default typing.
> But when deserialize the XML, the typing of primitive types (especially
> numeric and boolean) get lost.
>
> Every number and boolean is treated as string, when deserializing.
>
> java.lang.AssertionError: expected: java.lang.Integer<123> but was: java.
> lang.String<123>
>
> At the moment I manage with my own module and serializers for the
> primitive types.
> This works fine only with JsonTypeInfo.As.WRAPPER_OBJECT, but with
> JsonTypeInfo.As.WRAPPER_ARRAY, deserialization fails.
> Attached is a unit test and the module.
>
> But I wonder if there is not a better way?
>

Maps and XML are problematic as XML is inherently text based and has no
mechanism (in base XML specification, not including optional XML Schema
languages and definitions) for differentiating between numbers, strings and
booleans. Or between Arrays and Objects for that matter.

Couple of approaches you can use to start binding string values are:

1. Use of POJOs: Jackson can coerce String values into numbers (etc)
2. Two-pass processing: first into intermediate structures, then use your
own detection to derive numbers
3. Custom deserializer for `Map` type.

-+ Tatu +-

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to