tezozo / orika

Automatically exported from code.google.com/p/orika
0 stars 0 forks source link

Customize generated code to catch exception #99

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

We would like to customize the code generated by Orika. What we really need is 
to intercept an exception (say JDODetachedFieldAccessException) that is thrown 
by our model classes when we access some of the individual fields, during 
mapping-time. We don't want Orika to stop mapping because of that exception, 
just catch it and maybe return null for the field. Is there a way in Orika to 
intercept that, at a general level? If not, could it be considered for future 
implementation?

This comes from a topic at orika-discuss, but we feel it is more of an 
enhancement.
https://groups.google.com/forum/?fromgroups=#!topic/orika-discuss/bbH4JV-g3dc

Thanks in advance.

Original issue reported on code.google.com by ponteedu...@gmail.com on 6 May 2013 at 8:29

GoogleCodeExporter commented 8 years ago
This is the solution we are about to implement, unless something better and 
more framework-friendly is suggested:

1. extend SourceCodeContext with mapFields & compareFields methods such that 
the returned source code by super.mapFields() is wrapped in a try()/catch() 
block

2. extend MapperGenerator so that in its build() method instantiates an 
instance of our custom SourceCodeContext

3. extend DefaultMapperFactory so that in its constructor it instantiates an 
instance of our custom MapperGenerator

Original comment by ponteedu...@gmail.com on 7 May 2013 at 6:54

GoogleCodeExporter commented 8 years ago
Please refer to this reply 
https://groups.google.com/d/msg/orika-discuss/bbH4JV-g3dc/yhnXvLzYT-MJ

Original comment by Succe...@gmail.com on 7 May 2013 at 7:53