Closed MFlisar closed 8 years ago
Thanks. I will look into it!
Follow-Up question; What Serializer are you using? Something provided by me (gson or jackson) or something custom? I cannot reproduce it using Unit Tests locally. Neither gson nor jackson require Java Serializable Interface to serialize an Object to a json String.
My own implementation... Looks like following:
Setup
Esperandro.setSerializer(new Serializer() {
@Override
public String serialize(Object object) {
return StringUtil.serialize(object);
}
@Override
public <T> T deserialize(String serializedObject, Class<T> clazz) {
return StringUtil.deserialize(serializedObject, clazz);
}
});
And my StringUtil
class:
public static String serialize(Object object)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try
{
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(object);
oos.flush();
oos.close();
} catch (IOException e)
{
L.e(StringUtil.class, e);
}
return Base64.encodeToString(baos.toByteArray(), 0);
}
public static <T> T deserialize(String serializedObject, Class<T> clazz)
{
if (serializedObject == null)
return (T)null;
byte [] data = Base64.decode(serializedObject, 0);
Object o = null;
try
{
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data));
o = ois.readObject();
ois.close();
}
catch (IOException e)
{
L.e(StringUtil.class, e);
}
catch (ClassNotFoundException e) {
L.e(StringUtil.class, e);
}
return (T)o;
}
Ok, I see. I will add the Serializable
interface ASAP.
I just uploaded 2.3.0 to maven which fixes this problem. Should get synced in a few hours.
There's another problem:
Reading an uninitilised serialisable object fails, as adding the null value to the cache will fail with a java.lang.NullPointerException: key == null || value == null
exception...
Currently, if I use serializable lists, they are not working, as the generated code is wrapping a list in a container, that is NOT implementing serializable itself...
NOT Working: Using following does crash, as the wrapper class is not serializable:
working
With
OwnWrapper
like following: