ConfigOverride is a great option *i am **pleased* *to** know **th*
*at.*
Thanks a lot for your response,
On Monday, March 20, 2017 at 6:17:30 AM UTC+1, Tatu Saloranta wrote:
>
> Ok, first things first: I don't think you need to configure separate
> serializer/deserializer here, but call
>
> ObjectMapper.setDateFormat(new SimpleDateFormat(....))
>
> or alternatively, if you are using Jackson 2.8, may also define
> default format for Date:
>
> mapper.configOverride(Date.class)
> .setFormat(JsonFormat.Value.forPattern("....));
>
> These methods are more robust as they do not rely on knowing internals
> of serializer/deserializer.
>
> But as to registration approach: there is nothing special about
> registration, although you should just be using `SimpleModule` and not
> trying to add anything to `JavaTimeModule`. The only possible
> complication I can think of is that since there are 2 methods:
>
> public SimpleModule addSerializer(JsonSerializer<?> ser) { }
> public <T> SimpleModule addSerializer(Class<? extends T> type,
> JsonSerializer<T> ser) { }
>
> in latter case type bounds may make compiler complain without casts.
> If so, you would just need to cast serializer instance to have type
> `JsonSerializer<Date>`.
>
> I hope this helps,
>
> -+ Tatu +-
>
> ps. This is usage question, so really should go in `jackson-user`, not
> `jack
>
> On Thu, Mar 16, 2017 at 10:13 AM, Dam <[email protected] <javascript:>>
> wrote:
> > Hello,
> >
> > I declare a custom object mapper with a DateSerializer with a custom
> format
> > like this :
> >
> > public class CustomObjectMapper extends ObjectMapper
> > {
> > public CustomObjectMapper()
> > {
> > configure();
> > }
> >
> > private void configure()
> > {
> > super.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,
> > false);
> > JavaTimeModule module = new JavaTimeModule();
> > module.addSerializer(Date.class, new DateSerializer(false, new
> > SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")));
> > super.registerModule(module);
> > }
> > }
> >
> > And it's OK, but when I want to add a deserializer, I'm expected to do
> > something like this :
> >
> > module.addDeserializer(Date.class, new
> > DateDeserializer("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"));
> >
> > But it's doesn't work because the signature is :
> >
> >
> com.fasterxml.jackson.databind.deser.std.DateDeserializers.DateDeserializer.DateDeserializer(DateDeserializer
>
>
> > base, DateFormat df, String formatString)
> >
> >
> > What I have to put in "DateDeserializer base" and in String formatString
> ?
> > I suspect an inconsistency in the code or I don't understand the usage
> of
> > DateDeserializer ? Someone can help me ?
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups
> > "jackson-dev" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an
> > email to [email protected] <javascript:>.
> > For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"jackson-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.