Comments (12)
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.
Hey Greg - Do you have a simple test you could share that reproduces this?
from modelmapper.
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.
Yes, please share if you're able to reproduce the problem.
from modelmapper.
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.
here is a small example of what I am doing to clone. https://github.com/beachygreg/ModelMapperTest
from modelmapper.
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.
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.
I have the same probleme when I copy my Entity (from hibernate) to it's dto object.
Is there a solution ?
from modelmapper.
+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.
I'm also facing the same issue. Is there any alternative solution for this?
from modelmapper.
ModelMapper now support modelMapper.getConfiguration().setDeepCopyEnabled(true)
: #343
from modelmapper.
Related Issues (20)
- 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
- Basic Mapping doesn't work as expected.
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.