Dozer Custom-Converter instances

91 views
Skip to first unread message

foma....@gmail.com

unread,
Oct 23, 2014, 3:16:41 AM10/23/14
to dozer-...@googlegroups.com
Hello
I got a question regarding instances of custom converters.
Debugging I found out that dozer does not use the same instance of custom converter per request.

May I rest assured knowing that dozer uses a new instance of custom converter each time it is required so that, say, I can save some information in instance fields?
In other words may I use it as a statefull instance?
I didn't find anything about it in the documentation.
Or if I just missed it, could you please point me to the place in the docs?

Thank you.

Dmitry Buzdin

unread,
Nov 24, 2014, 10:46:49 AM11/24/14
to dozer-...@googlegroups.com
Hi,

It is possible to set instances of custom converters on DozerMapper object.

In this case mapper will take those instead creating new instance every time.

Regards,
Dmitry

четверг, 23 октября 2014 г., 10:16:41 UTC+3 пользователь foma....@gmail.com написал:

Harald Brabenetz

unread,
Nov 24, 2014, 3:51:59 PM11/24/14
to dozer-...@googlegroups.com
But be careful with the MapperAware interface.
AFAIK instead of storing the Mapper into an instance variable "Mapper mapper" you must store it into a ThreadLocal instance Variable "ThreadLocal<Mapper> mapper".
 
Reason:
The Mapper contains already mapped entities which will be used to solve circular dependencies.
If two mapping processes runs at the same time, and the same Converter instance is used, the entities could be mixed up.
 
Regards,
Harald
 
 
Gesendet: Montag, 24. November 2014 um 16:46 Uhr
Von: "Dmitry Buzdin" <buz...@gmail.com>
An: dozer-...@googlegroups.com
Betreff: Re: Dozer Custom-Converter instances
--
You received this message because you are subscribed to the Google Groups "Dozer Mapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dozer-mapper...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

foma....@gmail.com

unread,
Nov 26, 2014, 3:50:33 AM11/26/14
to dozer-...@googlegroups.com
So, in a simple case like the following:
<field custom-converter="com.example.Mapper">
      <a>aField</a>
      <b>bField</b>
</field>

Is it guaranteed that Dozer will create a new instance each time?

четверг, 23 октября 2014 г., 10:16:41 UTC+3 пользователь foma....@gmail.com написал:
Hello
Reply all
Reply to author
Forward
0 new messages