filtering a list before mapping

1,253 views
Skip to first unread message

declan roche

unread,
Jul 25, 2017, 7:07:43 AM7/25/17
to mapstruct-users

Hi,

I wonder can you help

I am trying to map tdfiTripcatches which is of type List<tdfiTripcatch>

To speciesOnBoard which is of type List<BaseSpecies>

I have a mapper tripCatchToBaseSpecies which does this and that part is working ok.

 

I would like to filter the list tdfiTripcatches and then apply the result which would also

Be a List<tdfiTripcatch>. To do this I am using a helper method getTripCatchListForSpeciesOnBoard

I am using the qualifiedByName pattern to do this but in the generated code I can see that the filter method

Is not being called.

 

I wonder does anyone know what is going wrong here

Any help appreciated

 

Regards,

Declan

 

 

@Mapper(componentModel="spring",

uses={

            ZonedDateTimeStampMapper.class,

            ConfigMapperFromId.class,

            TripEventToGeoInfoMapper.class,

            TripeventersMapper.class,

            TripCatchLocator.class

            },

            unmappedTargetPolicy = ReportingPolicy.IGNORE,

            nullValueCheckStrategy =  NullValueCheckStrategy.ALWAYS

)

 

 

public interface TripEventToPnoMapper {

      @Mappings(

                  {

                         @Mapping(target = "sequenceNum", source = "tripEvent.ersseqno"),

                        

                         @Mapping(target = "speciesOnBoard", qualifiedByName={"TripCatchLocator", "getTripCatchListForSpeciesOnBoard"}, source="tripEvent.tdfiTripcatches" )

                                           }

      )

      PriorNotificationOfReturnToPort tripEventToPno(Tripevent tripEvent);

     

     

      //map tripCatch entity to model object BaseSpecies

      @Mappings(

                  {

                         @Mapping(target = "speciesCode", source = "tripCatch.speciesid", qualifiedByName={"ConfigMapperFromId", "speciesCodeFromId"}),

                         ….

                  }

      )

      BaseSpecies tripCatchToBaseSpecies(TdfiTripcatch tripCatch);

     

     

}

 

 

 

 

@Component

@Named("TripCatchLocator")

public class TripCatchLocator {

 

      private ConfigurationService configService = ConfigurationServiceImpl.getInstance();

     

      @Named("getTripCatchListForSpeciesOnBoard")

      public List<TdfiTripcatch> getTripCatchListForSpeciesOnBoard(List<TdfiTripcatch> tripcatches) throws ConfigEntryNotFoundException{ 

           

            return getTripCatchesForType(tripcatches, configService.retrieveConfigIdFromCode("COB", "CatchType"));

      }

 

}

Gunnar Morling

unread,
Jul 26, 2017, 2:31:35 AM7/26/17
to declan roche, mapstruct-users
You could try to implement your filtering using a decorator: http://mapstruct.org/documentation/stable/reference/html/#decorators-with-spring

--Gunnar

--
You received this message because you are subscribed to the Google Groups "mapstruct-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapstruct-users+unsubscribe@googlegroups.com.
To post to this group, send email to mapstruct-users@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

declan roche

unread,
Jul 26, 2017, 3:41:45 AM7/26/17
to mapstruct-users, roche....@gmail.com
Hi Gunnar, 
Thanks for your reply. I could try the decorator pattern but I am already sucessfully  using the qualifiedByName pattern in other areas of my code so I would like to continue if possible. Do you know why mapstruct is not using my filter in this case?

Regards,
Declan
To unsubscribe from this group and stop receiving emails from it, send an email to mapstruct-use...@googlegroups.com.
To post to this group, send email to mapstru...@googlegroups.com.

Filip Hrisafov

unread,
Jul 27, 2017, 2:46:12 AM7/27/17
to mapstruct-users, roche....@gmail.com
Hi,

What does MapStuct actually create for this property?

Additionally, I don't know your object structure, but the getTripCatchListForSpeciesOnBoard maps from List<TdfiTripcatch> to List<TdfiTripcatch>. Shouldn't it be from List<TdfiTripcatch> to List<BaseSpecies>.

If TdfiTripcatch is from the inheriting BaseSpecies, then it is strange. Maybe it is some bug. If it is indeed inheriting, can you perhaps try the latest 1.2.0.CR1 and / or create e small reproducer that we could use to find the bug.

Cheers,
Filip
Reply all
Reply to author
Forward
0 new messages