Comments (5)
What objects are you mapping to each other? I guessed that you might be mapping CatalogOne to CatalogTwo which works out ok:
CatalogOne source = new CatalogOne();
source.label = "catalog1";
source.product = new ProductOne();
source.product.label = "product1";
source.product.catalog = source;
CatalogTwo dest = modelMapper.map(source, CatalogTwo.class);
assertTrue(dest.product instanceof ProductTwo);
assertEquals(dest.label, source.label);
assertEquals(dest.product.label, source.product.label);
assertEquals(dest.product.catalog, dest);
Let me know what your mapping looks like so I can reproduce your issue.
from modelmapper.
Hello Jonathan,
Yes for the mapping with the two concrete Catalogs. I do the mapping with ProductOne and ProductTwo too.
I know, it works with this simple example.
My real code is much more complex, i should work on it in a dichotomous way to eliminate the useless noise.
For the moment, I have replaced the implementation by Dozzer because we have not a lot of time to finish our application.
I find your api great to handle generics in the abstract classes, I will come back on the subject when I could take time to propose you a simple example which reproduces the issue.
Cheers
David
from modelmapper.
Hey David - Yes, please do post something that reproduces the issue you're hitting whenever you get a chance. It would be much appreciated.
from modelmapper.
Jonathan -- I think I can recreate this issue. I'm using 0.5.5. Here is my setup:
Company and Location objects map to CompanyModel and LocationModel. Company/CompanyModel has a property for Location/LocationModel. All objects have a Date field createdAt. ModelMapper throws configuration error because destination property Location.setCreatedAt() matches source property LocationModel.getCreatedAt() and CompanyModel.getCreatedAt(). I have explicitly mapped destination and source in PropertyMaps. I am using STRICT matching strategy.
public class Company {
private String name;
private Location location;
private Date createdAt;
//getters/setters removed for brevity
}
public class Location {
private String address;
private Date createdAt;
}
public class CompanyModel {
private String name;
private LocationModel location;
private Date createdAt;
}
public class LocationModel {
private String address;
private Date createdAt;
}
public class CompanyModelMap extends PropertyMap<CompanyModel, Company> {
@Override
protected void configure() {
//Explicit mappings for createdAt/updatedAt
map().setCreatedAt(source.getCreatedAt());
}
}
public class LocationModelMap extends PropertyMap<LocationModel, Location> {
@Override
protected void configure() {
//Explicit mappings for createdAt/updatedAt
map().setCreatedAt(source.getCreatedAt());
}
}
public class MapTest {
@Test
public void companyModelShouldMap() {
ModelMapper modelMapper = new ModelMapper();
modelMapper.getConfiguration()
.setMatchingStrategy(MatchingStrategies.STRICT);
modelMapper.addMappings(new CompanyModelMap()); //Exception thrown here
modelMapper.addMappings(new LocationModelMap());
Company company = new Company();
company.setName("Pepsi Co.");
Location location = new Location();
company.setLocation(location);
location.setAddress("1234 Main St.");
CompanyModel model = modelMapper.map(company, CompanyModel.class);
assertNotNull(model);
assertEquals(company.getName(), model.getName());
assertNotNull(model.getLocation());
assertEquals(company.getLocation().getAddress(), model.getLocation().getAddress());
}
}
org.modelmapper.ConfigurationException: ModelMapper configuration errors:
- The destination property com.github.modelmapper.test.Location.setCreatedAt() matches multiple source property hierarchies:
com.github.modelmapper.test.CompanyModel.getLocation()/com.github.modelmapper.test.LocationModel.getCreatedAt()
com.github.modelmapper.test.CompanyModel.getLocation()/com.github.modelmapper.test.CompanyModel.getCreatedAt()
1 error
at org.modelmapper.internal.Errors.throwConfigurationExceptionIfErrorsExist(Errors.java:225)
at org.modelmapper.internal.PropertyMappingBuilder.matchDestination(PropertyMappingBuilder.java:142)
at org.modelmapper.internal.PropertyMappingBuilder.matchDestination(PropertyMappingBuilder.java:135)
at org.modelmapper.internal.PropertyMappingBuilder.build(PropertyMappingBuilder.java:80)
at org.modelmapper.internal.TypeMapStore.getOrCreate(TypeMapStore.java:95)
at org.modelmapper.ModelMapper.addMappings(ModelMapper.java:92)
at com.github.modelmapper.test.MapTest.companyModelShouldMap(MapTest.java:25)
from modelmapper.
Thanks for reporting this. I found an issue with the way things were being handled when a match was found using the EXACT matching strategy. @dbundy and @jwicks Let me know if this does not solve your issue.
from modelmapper.
Related Issues (20)
- Error mapping, then reboot, works for a while
- How to skip not loaded Lazy fields?
- Test fails after upgrading from 3.1.0 to 3.1.1
- Java 21 support HOT 18
- Support of Java Module System
- Custom mapping in nested objects HOT 4
- Skip field of generic class HOT 1
- Mapping Source object to Destination object
- Mapping nested generic object with generic HOT 1
- Use specific converter for one field
- Model Mapper does not map values correctly (Intermittent - once in a few tries)
- Model Mapper Low performance
- Jackson Module: @JsonTypeInfo support for automatically handling inheritance HOT 1
- ModelMapper fails to map nested entity user field HOT 1
- When condition does not work for null-field
- How to ignore mapping errors HOT 1
- ModelMapper not working with nested generics
- modelmapper Hot deployment HOT 1
- How to Throw Validation exception when Source has a property that cannot be mapped to Destination HOT 1
- Test dependencies upgrade
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from modelmapper.