Comments (4)
I checked to see what mappings are created with each of the 3 matching strategies using ModelMaper 0.5.4:
for (Object o : modelMapper.getTypeMap(a.Down.class, b.Down.class).getMappings())
System.out.println(o);
And here's what we have:
STRICT:
PropertyMapping[Down.updateDate -> Down.updateDate]
STANDARD:
PropertyMapping[Down.pk.upId -> Down.pk.up.id]
PropertyMapping[Down.updateDate -> Down.updateDate]
LOOSE:
PropertyMapping[Down.pk.upId -> Down.pk.up.id]
PropertyMapping[Down.up.updateDate -> Down.pk.up.updateDate]
PropertyMapping[Down.updateDate -> Down.updateDate]
What mappings are you expecting?
from modelmapper.
Since I used MatchingStrategies.STRICT to map other child model, there is no way to change MatchingStrategies now.
And even I changed to LOOOSE,
for (Object o : modelMapper.getTypeMap(a.Down.class, b.Down.class).getMappings())
System.out.println(o);
prints right mapping, but the value was not assigned correctly. (updateDate)
Is there any way to set the mapping manually like this
PropertyMapping[Down.up.updateDate -> Down.pk.up.updateDate]
PropertyMapping[Down.updateDate -> Down.updateDate]
(under MatchingStrategies.STRICT)
I tried using() or configure , but none of them works.
from modelmapper.
It looks like the value for Down.updateDate is correctly assigned. I'm seeing the same result as you posted above:
Down [pk=null, updateDate=Fri Apr 03 00:00:00 PDT 3333]
MatchingStrategies are used when mappings are first created for a pair of types, which is when the TypeMap for a pair of types is first created. Once created, changing the MatchingStrategy has no effect. One solution is to create a different ModelMapper instance which will allow you to use a different matching strategy for a pair of types.
You can manually add additional mappings to a TypeMap using the mapping API:
http://modelmapper.org/user-manual/property-mapping/
Something like:
modelMapper.addMappings(new PropertyMap<a.Down, b.Down>() {
protected void configure() {
map().getPk().getUp().setId(source.getPk().getUpId());
}
});
from modelmapper.
Closing for now.
from modelmapper.
Related Issues (20)
- 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
- Basic Mapping doesn't work as expected.
- Generic mapping using reflection - ModelMapper HOT 1
- Bug: Property map is skipped when mapping multiple source properties to a nested target property using a converter.
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.