Skip to content

Instantly share code, notes, and snippets.

@luizjacomn
Created August 12, 2019 18:35
Show Gist options
  • Save luizjacomn/4e623ac28d713bdcee29474252dea998 to your computer and use it in GitHub Desktop.
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).
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