Created
August 12, 2019 18:35
-
-
Save luizjacomn/4e623ac28d713bdcee29474252dea998 to your computer and use it in GitHub Desktop.
Clone object using Jackson's library (allows modify properties without affects the original one).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public <T> T clone(Object obj, Class<T> clazz) throws Exception { | |
ObjectMapper objectMapper = new ObjectMapper(); | |
try { | |
return objectMapper.readValue(objectMapper.writeValueAsString(obj), clazz); | |
} catch (IOException e) { | |
throw new Exception(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment