Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializable problem #36

Closed
MFlisar opened this issue Nov 29, 2015 · 6 comments
Closed

Serializable problem #36

MFlisar opened this issue Nov 29, 2015 · 6 comments
Labels

Comments

@MFlisar
Copy link

MFlisar commented Nov 29, 2015

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:

ArrayList<String> existingSources();
boolean existingSources(ArrayList<String>existingSources);

working

OwnWrapper existingSources();
boolean existingSources(OwnWrapper  existingSources);

With OwnWrapper like following:

public static class OwnWrapper implements Serializable
{
    public ArrayList<String> sources;

    public OwnWrapper ()
    {
        sources = new ArrayList<>();
    }
}
@dkunzler
Copy link
Owner

dkunzler commented Dec 1, 2015

Thanks. I will look into it!

@dkunzler dkunzler added the bug label Dec 1, 2015
@dkunzler
Copy link
Owner

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.

@MFlisar
Copy link
Author

MFlisar commented Dec 20, 2015

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;
}

@dkunzler
Copy link
Owner

Ok, I see. I will add the Serializable interface ASAP.

@dkunzler
Copy link
Owner

I just uploaded 2.3.0 to maven which fixes this problem. Should get synced in a few hours.

@MFlisar
Copy link
Author

MFlisar commented Jan 25, 2016

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants