jackson-modules-base icon indicating copy to clipboard operation
jackson-modules-base copied to clipboard

Make mr bean implement `clone()` method

Open TuomasKiviaho opened this issue 7 years ago • 5 comments

Cloning of the internal structure (HashMap I presume) would be possible just like equals and hashCode have no been dealt with. If there is an abstract implementation already present then the call to super will take care of that. Support of course only works when Cloneable interface is present.

TuomasKiviaho avatar Jan 25 '18 07:01 TuomasKiviaho

@TuomasKiviaho wonder if this went to wrong repo... ? If not, I'd need bit more detail. clone() is not generally implemented by Jackson components, unless needed internally, hence guessing might not belong here.

cowtowncoder avatar Jan 25 '18 18:01 cowtowncoder

wonder if this went to wrong repo... ?

I wondered that a while myself after reading this but then I remembered that MrBean is now under this repo so the location is right but the description was too vague.

clone() is not generally implemented by Jackson components, unless needed internally, hence guessing might not belong here.

Actually now that I've actually read how you do things with the new ByteBuddy approach, the cloning might be supported after all out of the box. The internal structure is not a map as I though first, but the state is kept in individual fields and hence the equals/hash methods have to be created separately. But for cloning and why not for standard serialization as well this approach would work out-of-the-box.

I'll close the issue.

TuomasKiviaho avatar Jan 29 '18 07:01 TuomasKiviaho

@TuomasKiviaho Ok. I am just curious as to what the specific use case is -- not so much questioning the need (since I don't know usage :) ), but understanding the context.

But from above I guess you'd be asking for Mr Bean to generate clone() for value classes generated? Which would seem reasonable, similar to #2 and #3. (and/or possibly configurable for module).

cowtowncoder avatar Jan 29 '18 18:01 cowtowncoder

You guessed the use case correctly and as I was writing the clarification I realized that if my abstract class implements the Cloneable then I'd propably be able to fulfill the use case already. Module support would indeed be needed for interface support because default clone method can't call super.clone() and transient field declarations would need some sort of callback hooks.

TuomasKiviaho avatar Jan 30 '18 05:01 TuomasKiviaho

How about I reopen this issue since it seems like a worthy improvement idea. Thanks for clarification!

cowtowncoder avatar Jan 30 '18 19:01 cowtowncoder