Problem serializing model classes with jackson

48 views
Skip to first unread message

Emanuele Ziglioli

unread,
Jan 15, 2014, 5:22:16 PM1/15/14
to siena-...@googlegroups.com
Hi Siena users, I'm sure there are stil a couple out there.

I'me experimenting with Google Cloud Endpoints, and am having trouble serializing siena classes. They use Jackson, and that tries to serialize public getters, such as 

public final PersistenceManager getPersistenceManager()
public Relation getRelation()


Does anybody know a method to tell Jackson to skip getters()?
Google is repackaging Jackson, so I wouldn't be able to add @JsonIgnore into Siena without using their repackaged annotation.
Plus, Siena shouldn't have external dependencies, or at least I thought that was the reason why Json serialization was implemented by Siena itself.


Can't override getPersistenceManager() though (to add the annoation), as it's marked as final. Of course I can always change it...

Have started a thread on Plus about it: https://plus.google.com/+EmanueleZiglioli/posts/5bYytiELVkd

Emanuele Ziglioli

unread,
Jan 19, 2014, 5:48:36 PM1/19/14
to siena-...@googlegroups.com
Solved for now by overriding Siena's Model class and by adding @JsonIgnore to noserializable public fields and getters.
Probably the best solution is using mixins, but that would apply to a Jackson solution, not a repackaged version like they use with Google Cloud Endpoints

Emanuele Ziglioli

unread,
Jan 29, 2014, 9:46:14 PM1/29/14
to siena-...@googlegroups.com
Having a different problem now, using MapReduce, at a certain point they try to serialize an object containing a Siena model

void java.io.ObjectOutputStream.writeObject(Object obj) throws IOException

I get 
  java.io.NotSerializableException: siena.Model$ProxyOne

I believe siena populates the field relation with an instance (in my case) the inner class ProxyOne.
I see in siena.Model there's a comment

// this is a technical field used by Siena to represent a relation
// between this model and another one. For ex, it will be used to
// identify the ancestor in an aggregation relation
// has transient modifier to prevent serialization FOR THE TIME BEING
// TODO IS THE TRANSIENT REQUIRED OR CAN IT BE A PB?
@Aggregator
private Relation relation;

Other than removing my Model field from the class they're trying to serialize, I thought I could solve the problem by either:
1. adding volatile to "relation"
2. declaring the inner classes as static
3. declaring the inner classes as serializable, and implement serialize().

Tried 1., had other problems, not sure why it didn't work.
Will think again and if I find a solution I'll post it here, for other users (he he, anybody there?)

Emanuele Ziglioli

unread,
Jan 29, 2014, 10:04:50 PM1/29/14
to siena-...@googlegroups.com
The problem is from a "One" member in my model, that becomes a concrete ProxyOne.
Making ProxyOne static and serializable doesn't help because that class contains a Field member that is not serializable.
I don't wanna make the One member in my model "transient" because that would prevent Siena from persisting it. 
It's an old problem, I wonder whether there's a way to make a field non serializable but still peristent.

I'll put this problem in the too hard basket for now and work around it.

Emanuele Ziglioli

unread,
Feb 17, 2014, 2:35:50 PM2/17/14
to siena-...@googlegroups.com
I've stumbled on this problem again when I was setting a deferred task on GAE and some of the parameters were Siena models, that were not serializable due to some Many and One relationships.
I've marked all those fields to "transient" and indeed it worked but then it failed when I got to query on those fields that after serialization were null.

So I guess I need to understand a bit how Many and One work and see if I can write a custom serialization for them
Reply all
Reply to author
Forward
0 new messages