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

Add support for entity specified with Immutables.org #5

Open
pogo19 opened this issue Jun 7, 2016 · 2 comments
Open

Add support for entity specified with Immutables.org #5

pogo19 opened this issue Jun 7, 2016 · 2 comments

Comments

@pogo19
Copy link

pogo19 commented Jun 7, 2016

Hi!

In my project I've recently changed from POJO to Immutables.org. As far as I got, java-dirty doesn't support it. It would be great to support Immutables.org or custom (de)serialization.

Thanks!

Jan

@mrwilson
Copy link
Owner

mrwilson commented Jun 7, 2016

Hi Jan,

Can you give an example of where storing an Immutables.org object fails? I've never used this library.

Thanks!

Alex

@pogo19
Copy link
Author

pogo19 commented Jun 7, 2016

I have a class annotated for generation by Immutables.org, Event.java

@SuppressWarnings("serial")
@Immutable
@Gson.TypeAdapters
public abstract class Event<K, T> implements Serializable {

    @Parameter
    public abstract String getUuid();

    @Parameter
    public abstract long getTimestamp();

    @Parameter
    public abstract int getSchemaVersion();

    @Parameter
    public abstract EventType getType();

    @Parameter
    public abstract String getOriginator();

    @SuppressWarnings("rawtypes")
    @Parameter
    public abstract Class getPayloadIdClass();

    @Parameter
    @Nullable
    public abstract K getPayloadId();

    @SuppressWarnings("rawtypes")
    @Parameter
    public abstract Class getPayloadClass();

    @Parameter
    @Nullable
    public abstract T getPayload();

}

Immutables.org then as a port of java compilation generates ImmutableEvent.java and it is compiled. This ImmutableEvent is standard class extending Event.

When I use directly Event.class in Store.of(), it doesn't know how to handle abstract class. If I use ImmutableEvent.class than I get this error.

java.lang.IllegalAccessException: Class uk.co.probablyfine.dirty.Store can not access a member of class xxx.yyy.zzz.ImmutableEvent with modifiers "private final"
    at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)
    at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:296)
    at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:288)
    at java.lang.reflect.Field.get(Field.java:390)
    at uk.co.probablyfine.dirty.Store.lambda$null$2(Store.java:60)
    at uk.co.probablyfine.dirty.utils.Exceptions.unchecked(Exceptions.java:20)

Does java-dirty support custom Java objects serialization? Also my Event object has another object (also Immutable) as an attribute (getPayload()), so that the serialized form size can change depending on type of payload object.

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

No branches or pull requests

2 participants