On Sat, Jul 6, 2019 at 1:20 AM 'Johannes Paul' via jackson-user < [email protected]> wrote:
> I would like to deserialize a JSON to an Object, which holds a Object > named 'data'. I want everything to be stored as a string, to deserialize it > later. > The reason is, i dont know the exact target class for the data, if the > data arives, but to get the exact class, i first need the rest of the JSON > deserialized. > > I Posted a question on StackOverflow wich explains the issue a bit more > and provides a working code example (except getter and setter). > > Is there any chance to get the content ob a object/array as a String > through the JsonParser in a JsonDeserializer? > > If you mean whether you can try get "raw" content of JSON values of any type as `java.lang.String`, no -- parser will decode content into tokens, and it would not make sense to then try to create JSON again. But you don't have to do that anyway: instead, declare target as `JsonNode` (to get a tree representation), or either `Map` (if known to be JSON Object) or `Object`, and you will get "untyped" structure (Map, List, String, Number, Boolean). Either way you can then convert from that type into whatever you decide eventual target to be, based on other information. Conversion method to use is either `convertValue()` (with Map/Object), or `treeToValue()` (for `JsonNode`). -+ 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]. To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/CAGrxA27J0ZSpMmtRN3jXRM_pzJE42Er34s6Q%3DeoHjs4zStYj2Q%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
