Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variant of ObjectMapper.convertValue() that does "Deep Copy" (Clone) #2007

Open
akefirad opened this issue Apr 23, 2018 · 1 comment
Open
Labels
3.0 Issue planned for initial 3.0 release

Comments

@akefirad
Copy link

akefirad commented Apr 23, 2018

cc: @cowtowncoder
I saw people using Jackson to do it, but in a not-so-efficient way:

MyPojo myPojo = new MyPojo();
ObjectMapper mapper = new ObjectMapper();
MyPojo newPojo = mapper.readValue(mapper.writeValueAsString(myPojo), MyPojo.class);

I know about ObjetMapper.convertValue method, but the problem is that it returns the original value is of the given type:

...
            Class<?> targetType = toValueType.getRawClass();
            if (targetType != Object.class
                    && !toValueType.hasGenericTypes()
                    && targetType.isAssignableFrom(fromValue.getClass())) {
                return fromValue;
            }
...

And also the note is the documentation which reads:

Note that it is possible that in some cases behavior does differ from full serialize-then-deserialize cycle

So can we have (an overloaded version of) convertValue (or a new method) to behave totally as deep copy?

@cowtowncoder cowtowncoder added the 3.x Issues to be only tackled for Jackson 3.x, not 2.x label May 24, 2018
@cowtowncoder cowtowncoder changed the title Deep Copy (Clone) Feature Variant of ObjectMapper.convertValue() that does "Deep Copy" (Clone) Jul 28, 2022
@cowtowncoder cowtowncoder added 3.0 Issue planned for initial 3.0 release and removed 3.x Issues to be only tackled for Jackson 3.x, not 2.x labels Dec 1, 2024
@cowtowncoder
Copy link
Member

As per #2220 short-cut no longer applied, so this is probably no longer needed?
Will leave open for a bit before closing to think this over.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.0 Issue planned for initial 3.0 release
Projects
None yet
Development

No branches or pull requests

2 participants