discomarathon / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

Add @PreSerialize annotation #163

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
1.remove unused field value
public class User{
private String username;
private String password;
@PreSerialize
public void preSerialize(){
this.password = null;
}
}

2.set getter's value to field
because gson doesn't support serialize getter method

public class TreeNode{
private Collection<TreeNode> children;
private boolean hasChildren;
@PreSerialize
public void preSerialize(){
this.hasChildren = isHasChildren();
}
public boolean isHasChildren(){
return this.children != null && this.children.size() != 0;
}
}

Original issue reported on code.google.com by zhouyanm...@gmail.com on 10 Oct 2009 at 2:50

GoogleCodeExporter commented 9 years ago
Sorry, but I do not fully understand the requirements for this new PreSerialize
annotation.

This could done similar to the PostCreate (Issue #144) or it could be done with 
a
TypeConverter where you can do some special behaviour and than use the
SerializationContext and serialize this (Issue #43).

Original comment by joel.leitch@gmail.com on 10 Oct 2009 at 4:17

GoogleCodeExporter commented 9 years ago
I can't find @PostCreate,I think it's for deserialization not serialization
TypeConverter need exact class
registerTypeAdapter(Foo.class, new FooTypeAdapter()) doesn't works for subclass 
of Foo
it must be 
registerTypeAdapter(ChildOfFoo.class, new 
FooTypeAdapter()).registerTypeAdapter(Child2OfFoo.class, new 
FooTypeAdapter()).registerTypeAdapter(Child3OfFoo.class, new 
FooTypeAdapter())....

Original comment by zhouyanm...@gmail.com on 10 Oct 2009 at 6:40

GoogleCodeExporter commented 9 years ago
I have a patch,please see 
http://code.google.com/p/google-gson/issues/detail?id=164

Original comment by zhouyanm...@gmail.com on 10 Oct 2009 at 6:58

GoogleCodeExporter commented 9 years ago

Original comment by inder123 on 3 Nov 2010 at 12:29

GoogleCodeExporter commented 9 years ago
Let's fix issue 164 instead.

Original comment by limpbizkit on 3 Nov 2010 at 5:30