cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Custom serializer for DTO

0 Likes
902

Hi experts! Does anybody know the way we could declare DTOs via beans.xml using custom serializer? For instance, I need support a range of formats of Date, that comes in json format. Currently it is implemented via extending JsonDeserializer and using list of parsers via java class:

    private static final DateTimeFormatter FORMATTER = new DateTimeFormatterBuilder()
                .append(null, PARSERS).toFormatter(); 

and then we're able to use it in annotations of declared DTOs like:

     @JsonDeserialize(using = CustomJsonDateDeserializer.class) 

But via declaration in beans.xml there is no chance to use this way.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Likes

We have same issue to allow different DateFormat. Did you find a solution to include Custom Deserializer class in beans.xml?

aimprosoft
Participant
0 Likes

Hi Dmytro,

beans.xml allow us to declarate the default annotations with using annotations tag

<property name="date" type="java.util.Date">
   <annotations>
      @JsonDeserialize
   </annotations>
</property>

I believe that there are should be ability to set into it your custom deserializer or set default (i.e. DateDeserializer) but extend it via your custom...

<bean class="com.test.facades.data.MyTestData">
   <import type="com.fasterxml.jackson.databind.annotation.JsonDeserialize"/>
   <import type="com.fasterxml.jackson.databind.deser.std.DateDeserializers"/>
   <property name="date" type="java.util.Date">
      <annotations>
         @JsonDeserialize(using=DateDeserializers.DateDeserializer.class)
      </annotations>
   </property>
</bean>

hope this helps,

Igor