Always show null object to null

I am looking for a way to map each nullable object to null instead of an error "org.dozer.MappingException: Source object must not be null"

. I don't want to list every class and say null maps are zero, I want to point this out as a general rule.

+3


source to share


1 answer


This is one common exception, which says that you should not pass a null object as a top-level bean to the mapper.map (src, dest) method. Thus, it is necessary to check the security before calling Dozer.

if (src == null) return null;
return dozer.map(src, dest);

      



Also, the "map-null" policy is enabled by default, but it only applies to the elements inside the bean that you want to display (not at the top level). Therefore Dozer will render correctly 'user.id'

if it is null. In the next version, it will be possible to apply "map-null" globally without specifying each class. However, it can help to disable the display of zeros as it is enabled by default.

+5


source







All Articles