Exception when adding a custom mapping

1,196 views
Skip to first unread message

Sascha Ißbrücker

unread,
Mar 27, 2013, 8:02:00 PM3/27/13
to model...@googlegroups.com
Hi,

I was just playing with ModelMapper and it looks pretty cool so far. Good job!

However when I try to add a custom mapping to the mapper it throws an exception.

Custom mapping:

        PropertyMap<User, DUser> userMap = new PropertyMap<User, DUser>() {

            @Override
            protected void configure() {
                map().roleCount = source.getRoles().size();
            }
        };

Configuring the mapping throws exception:

        modelMapper.addMappings(userMap);


Exception:

Exception in thread "main" org.modelmapper.ConfigurationException: ModelMapper configuration errors:

1) A mapping is missing a required destination method.

1 error
at org.modelmapper.internal.Errors.throwConfigurationExceptionIfErrorsExist(Errors.java:226)
at org.modelmapper.internal.MappingBuilderImpl.build(MappingBuilderImpl.java:137)
at org.modelmapper.internal.TypeMapImpl.addMappings(TypeMapImpl.java:71)
at org.modelmapper.internal.TypeMapStore.getOrCreate(TypeMapStore.java:93)
at org.modelmapper.ModelMapper.addMappings(ModelMapper.java:92)
at Main.initializeModelMapper(Main.java:169)
at Main.main(Main.java:25)

So, not sure if I'm doing something wrong? The only thing I can think of is that field matching is enabled (enableFieldMatching(true))? 

I have pushed my code a (temporary) GitHub repo, if you want to take a look at it: https://github.com/sissbruecker/model-mapper-propertymap-error

Thanks,

Sascha

Jonathan Halterman

unread,
Mar 27, 2013, 8:22:27 PM3/27/13
to model...@googlegroups.com
Hey Sascha,

Unfortunately there's no (easy) way to do field mapping like you were going for, so the mapping of two properties has to be done via getter/setter method pairs such as:

map().setRoleCount(source.getRoles().size());

Try something like that.

Cheers,
Jonathan

Sascha Ißbrücker

unread,
Mar 28, 2013, 5:36:32 PM3/28/13
to model...@googlegroups.com
Ok, there's no real reason for not generating these getters/setters anyway.

Thanks!

kathire...@gmail.com

unread,
Aug 9, 2016, 1:32:22 AM8/9/16
to modelmapper

Hi,

I'm getting the same exception but the problem is not resolved after the suggestion. solution.

Any idea?

Thanks.
Reply all
Reply to author
Forward
0 new messages