Git Product home page Git Product logo

Comments (12)

chhsiao90 avatar chhsiao90 commented on July 22, 2024 2

Yeah..
The problem might be caused by AssignableConverter in ConverterStore

Currently, it seems to be hard to disable the converter because

  • AssignableConverter have no configuration
  • The method match only have source type and destination type as the arguments
  • There is no nice way to config the converter store

The workaround might be to remove the converter manually.
Not very recommend, but please to have some complete test if you want to try it.

  // really ugly workaround
  ConditionalConverter<?, ?> assignableConverter = null;
    for (ConditionalConverter<?, ?> converter : modelMapper.getConfiguration().getConverters()) {
      if (converter instanceof  AssignableConverter) {
        assignableConverter = converter;
        break;
      }
    }
    if (assignableConverter != null) {
      modelMapper.getConfiguration().getConverters().remove(assignableConverter);
    }

from modelmapper.

jhalterman avatar jhalterman commented on July 22, 2024

Hey Greg - Do you have a simple test you could share that reproduces this?

from modelmapper.

beachygreg avatar beachygreg commented on July 22, 2024

Hi Jonathan,

I can not release my source as its core business. So I create a project to reproduce this.. but I can not seem to reproduce. So will try to see what is going on and will let you know if its just me doing something wrong.

Thanks,
Greg

from modelmapper.

jhalterman avatar jhalterman commented on July 22, 2024

Yes, please share if you're able to reproduce the problem.

from modelmapper.

beachygreg avatar beachygreg commented on July 22, 2024

To give a little background, I am using your library to clone objects. It is really nice for this as it is easy to detach objects from the hibernate session and also give new or blank keys to objects.

I did not realize that the same object is returned if you do not provide a PropertyMap for a given object to the same object... It would be nice feature to re instantiate the object regardless off a property map being passed for the object (would only really be good for my use case).

Thanks,
Greg B.

from modelmapper.

beachygreg avatar beachygreg commented on July 22, 2024

here is a small example of what I am doing to clone. https://github.com/beachygreg/ModelMapperTest

from modelmapper.

beachygreg avatar beachygreg commented on July 22, 2024

If there was a setting that allows new objects being created regardless, it would be very easy to use ModelMapper to clone objects.

from modelmapper.

jhalterman avatar jhalterman commented on July 22, 2024

Hey Greg,

I'm not sure what you mean when you say "that the same object is returned if you do not provide a PropertyMap for a given object to the same object". Can you explain further?

from modelmapper.

mzamoun avatar mzamoun commented on July 22, 2024

I have the same probleme when I copy my Entity (from hibernate) to it's dto object.
Is there a solution ?

from modelmapper.

dr3s avatar dr3s commented on July 22, 2024

+1 it would nice if it was configurable to always create new objects when mapping properties such that it is easy to do a deep clone. Currently, mapping from:

public class A {
   private B b;
}

to:

public class C {
   private B b;
}

results in a.b == c.b

from modelmapper.

RajuGR avatar RajuGR commented on July 22, 2024

I'm also facing the same issue. Is there any alternative solution for this?

from modelmapper.

chhsiao90 avatar chhsiao90 commented on July 22, 2024

ModelMapper now support modelMapper.getConfiguration().setDeepCopyEnabled(true): #343

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.