Skip to content

Instantly share code, notes, and snippets.

@veysiertekin
Last active February 13, 2017 00:05
Show Gist options
  • Save veysiertekin/1f5ddf6923a6b1de8c8a to your computer and use it in GitHub Desktop.
Save veysiertekin/1f5ddf6923a6b1de8c8a to your computer and use it in GitHub Desktop.
Example usage of Kryo's clone function (Kryo repo: EsotericSoftware/kryo)
import com.esotericsoftware.kryo.Kryo;
import org.objenesis.strategy.StdInstantiatorStrategy;
...
public static <T> T clone(T object) {
// Kryo is not thread safe...
Kryo kryo = new Kryo();
try {
kryo.setAsmEnabled(true);
// kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());
((Kryo.DefaultInstantiatorStrategy) kryo.getInstantiatorStrategy()).setFallbackInstantiatorStrategy(new StdInstantiatorStrategy());
return kryo.copy(object);
}
finally {
// for improving performance
kryo = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment