Error to <nulltype> cannot be converted to long

900 views
Skip to first unread message

Michel Barret

unread,
Apr 2, 2015, 11:58:10 AM4/2/15
to selma...@googlegroups.com
Hello,

I try to use selma to map 2 POJO and I give this error :
HubMapperSelmaGeneratedClass.java:[20,25] incompatible types: <nulltype> cannot be converted to long

My source POJO have few fields int and string, one Date and 2 Map<String, Date>.
My destination POJO have fields int and string, one Long and 2 Map<String, Long>.

The fields are exactly the same name.

@Mapper(withCustom = DateMapper.class)
public interface PojoMapper {
 
POJODest asPOJODest(POJOSrc src);
}

and

public class DateMapper {
 
public Long dateAsLong(Date date) {
   
return date.getTime();
 
}

 
public Date longAsDate(Long timestamp) {
   
return new Date(timestamp);
 
}
}

In compile time, I get the message
HubMapperSelmaGeneratedClass.java:[20,25] incompatible types: <nulltype> cannot be converted to long

I try with ignoreNotSupported = true and with withIgnoreMissing = IgnoreMissing.ALL and I have always the same result.

Can you help me to fix it ?

Séven Le Mesle

unread,
Apr 3, 2015, 5:22:28 PM4/3/15
to selma...@googlegroups.com
Hi, 

I am trying to reproduce the error.  Can you provide the HubMapperSelmaGeneratedClass source ?

There should be some bug in the generated code. 

The ignoreNotSupported should not be used, it is just a way to throw IllegalArgumentException when Selma does not know how to map a specific field.
The ignoreMissing will disable any error / warning compiler report in case there are fields not present in both source and destination class.  

Séven

Séven Le Mesle

unread,
Apr 3, 2015, 7:52:27 PM4/3/15
to selma...@googlegroups.com
Ok I've got it, 

one of your setter method in the destination bean uses a long instead of a Long. 
You just need to make sure that you use same type for setter and result type of your custom mapper.
The problem comes from bad null safety code in Selma. 
I've open this issue to solve the error https://github.com/xebia-france/selma/issues/51

The bug is fixed in snapshot build, can you confirm it solves your error ?

Séven

Michel

unread,
Apr 4, 2015, 1:06:35 PM4/4/15
to Séven Le Mesle, selma...@googlegroups.com
Hi !

It's exactly that ! Thank you for your help !

Regards,
Reply all
Reply to author
Forward
0 new messages