I'm trying to implement a simple serializer to use with my custom class.
I know my class can be serialized to JSON (I have done it elsewhere), so I thought this would be an easy way to go. However, on startup, when it is referenced as a .valueSerializer() , I get:
java.lang.IllegalArgumentException: Not serializable: class com.x.y.ext.JSONMapSerializer$2
at org.mapdb.SerializerBase.assertSerializable(SerializerBase.java:1482)
at org.mapdb.DB.createHashMap(DB.java:415)
at org.mapdb.DB$HTreeMapMaker.make(DB.java:216)
at org.mapdb.DB$HTreeMapMaker.makeOrGet(DB.java:222)
Not sure why. The actual code is as follows:
public static final Serializer<Favorites> FAVORITES_SERIALIZER = new Serializer<Favorites>()
{
@Override
public void serialize(DataOutput dataOutput, Favorites favorites)
throws IOException
{
Gson gson = new Gson();
dataOutput.writeUTF(gson.toJson(favorites));
}
@Override
public Favorites deserialize(DataInput dataInput, int i)
throws IOException
{
Gson gson = new Gson();
return gson.fromJson(dataInput.readUTF(), Favorites.class);
}
@Override
public int fixedSize()
{
return 0;
}
};
It's probably not tremendously fast, but I don't need it to be in my case...just need it to work. :)
Thanks for any hints/tips/tricks!
-AJ