On Fri, Sep 28, 2018 at 6:34 AM Tristan Lins <[email protected]> wrote: > > Unfortunately I can not use POJOs because the data structure is completely > defined by the user. > > And a custom map deserializer is unfortunately difficult to implement because > the standard MapSerializer is not extendable. > Too many private and final methods :-( > > I'll probably do it now with wrapper objects. > However, I will change the whole Map to Map<String,Value> or something like > that. > The map is anyway only for transport and does not belong to a public API. > Then I do not have to do any transformation of the map. > > Thank you very much for your feedback!
Sorry I couldn't be of much more help. XML is tricky, but I hope you can get things to work. -+ Tatu +- > > Am Freitag, 28. September 2018 07:32:45 UTC+2 schrieb Tatu Saloranta: >> >> 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. -- 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.
