kryo.readObject cause NullPointerException with ArrayList

With kryo version 2.24, calling

kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());

overrides the default instantiator strategy which uses the class no argument constructor if present. The correct way to do this is to call:

((Kryo.DefaultInstantiatorStrategy) kryo.getInstantiatorStrategy()).setFallbackInstantiatorStrategy(new StdInstantiatorStrategy());

This is explained here https://github.com/EsotericSoftware/kryo

I think this has changed since version 2.21


I was getting a similar null pointer exception and I needed to add a custom serializer from: https://github.com/magro/kryo-serializers

Ex:

kryo.register( Collections.EMPTY_LIST.getClass(), new CollectionsEmptyListSerializer() );

Tags:

Java

Kryo