Git Product home page Git Product logo

Comments (4)

jhalterman avatar jhalterman commented on July 22, 2024

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.

intree avatar intree commented on July 22, 2024

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.

jhalterman avatar jhalterman commented on July 22, 2024

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.

jhalterman avatar jhalterman commented on July 22, 2024

Closing for now.

from modelmapper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.