Using modelmapper in hippocms 13

In our current project we are using modelmapper (http://modelmapper.org) to map hippo documents to data transfer objects. Before hippo 13 this used to work as expected, but since hippo 13 the HstLinkImpl class is only available in the platform (cms). Modelmapper tries to instantiate the HstLinkImpl and that fails.

What is the best practise in hippo 13 to do this kind of transformations?

Hi Leon,

Indeed the HstLinkImpl class has moved to the platform (cms) webapp. Wrt ‘Modelmapper tries to instantiate the HstLinkImpl and that fails.’ , I assume you have created a Modelmapper mapping yourself and use HstLinkImpl, isn’t? Before version 13, the HstLinkImpl was part of hst-core, which was indeed part of your site webapp but by default you did not have a compile dependency against the hst-core, so you could not by default have used something like HstLinkImpl.class without changing the hst-core dependency scope (it was runtime). Could you post me the code example that used to work but does not work any more in version 13? Do you get compile time issues or is it runtime?

Note I am not familiar with modelmapper.org.

Regards Ard

Hi Ard,

I am getting a runtime exception. Here is the code snippet:

/**

  • Converts a hippo link to a fully qualified url
    */
    @Slf4j
    public class HstLinkToUrlConverter extends AbstractConverter<HstLink, String> {

    @Override
    protected String convert(HstLink link) {
    if (link != null) {
    HstRequestContext hstRequestContext = RequestContextProvider.get();

         return link.toUrlForm(hstRequestContext, true);
     }
    
     return "";
    

    }
    }

ModelMapper modelMapper = new ModelMapper();
TypeMap<HippoBean, ItemDto> itemMapper = modelMapper.createTypeMap(HippoBean.class,ItemDto.class);

HstLinkToUrlConverter urlConverter = new HstLinkToUrlConverter();
itemMapper.addMappings(mapper -> mapper.using(urlConverter).map(HippoBean::getLink,ItemDto::setId));

Since modelmapper does not work with interfaces it tries to instantiate the concrete class in this case the HstLinkImpl.class.

Hope this clarifies my problem.

Best Regards,

Leon Jongsma

Hi Leon,

Leon_Jongsma
January 15

Hi Ard,

I am getting a runtime exception. Here is the code snippet:

/**

Converts a hippo link to a fully qualified url
*/
@Slf4j
public class HstLinkToUrlConverter extends AbstractConverter<HstLink, String> {

@Override
protected String convert(HstLink link) {
if (link != null) {
HstRequestContext hstRequestContext = RequestContextProvider.get();

 return link.toUrlForm(hstRequestContext, true);

}

return “”;
}
}

ModelMapper modelMapper = new ModelMapper();
TypeMap<HippoBean, ItemDto> itemMapper = modelMapper.createTypeMap(HippoBean.class,ItemDto.class);

HstLinkToUrlConverter urlConverter = new HstLinkToUrlConverter();
itemMapper.addMappings(mapper → mapper.using(urlConverter).map(HippoBean::getLink,ItemDto::setId));

HippoBean doesn’t have a ‘getLink()’ method AFAIK…not sure how the
above could ever work before?

Since modelmapper does not work with interfaces it tries to instantiate the concrete class in this case the HstLinkImpl.class.

How does the modelmapper ‘know’ that it should/try to instantiate
HstLinkImpl.class? It has to be told someway isn’t? so where is this
configured?

Can you also mail the runtime stacktrace you are getting?

Regards Ard