Skip to content
Advertisement

nullValuePropertyMappingStrategy not working

I have the following mapper

JavaScript

The pokerRoomDto which is passed to it has a “phase” field which can be null. I want this field to be ignored when it is null. But right now the “null” value still gets mapped to the pokerRoom entity.

If I just ignore the field in the mapper it works and the default value for phase in PokerRoom stays untouched however I dont want to always ignore it.

JavaScript

Advertisement

Answer

This works as designed. NullValuePropertyMappingStrategy is only applied to update method. It is not used for normal mappings.

I think that you are looking for NullValueCheckStrategy, if you use NullValueCheckStrategy#ALWAYS then MapStruct will always do a null check non the PokerRoomDto and only invoke the setter on the PokerRoom if the value was not null

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement