On Sun, Feb 11, 2018 at 8:11 AM, Anindya Chatterjee <[email protected]> wrote: > I have an unique requirement. I like to determine if an object of a given > type can be serialized into a value depending on the registered module in > ObjectMapper. > > The code should work as follows: > > > public boolean canConvertToValue(Class<?> type) { > // code goes here > } > > //result as follows > canConvertToValue(SomeType.class) = false > canConvertToValue(String.class) = true > canConvertToValue(LocalDateTime.class) = false // when JavaTimeModule is > not registered > canConvertToValue(LocalDateTime.class) = true // when JavaTimeModule is > registered > > How do I implement canConvertToValue() using jackson? Or is that impossible > to implement? >
There is no such functionality because any type can (in theory) be serialized like a POJO. There is no way to know, for example, that for `LocalDateTime` this is not the best way to do it. Similarly there is no reliable way to see if a type could be deserialized: checks could perhaps be added to ensure there is a constructor, but even that gets complex and gives false positives easily. There are methods `canSerialize()` and `canDeserialize()` in ObjectMapper in 2.x, but I have removed them from 3.0 since they really achieve very little. -+ 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.
