discomarathon / google-gson

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

Updating of existing entities during deserialization instead of creating new ones #176

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I need to update existing entity from json data instead of creating new one.
For example i have some entity like this one:
Entity {
  int id;
  String value1;
  String value2;
}
and json like {"value2":"newValue"}
I whould like to update only value2 in such object leaving id and value1 as 
they are.

This can be achieved by two ways:
a) provide a new method in Gson class like this one:
public void fromJson(String jsonText, Object exitsingEntity);
b) private access to property values in InstanceCreator, for example
public T createInstance(Type type, <some way to get values for this object from 
json string>);

a) should not be hard to implement

Original issue reported on code.google.com by zlow...@gmail.com on 20 Nov 2009 at 3:26

GoogleCodeExporter commented 9 years ago
a) is not a general solution. What if you wanted to replace a value deep-down 
in the 
Json tree. 

Regarding b) I suppose you can already write an InstanceCreator that keeps 
track of 
all the objects of type Entity and gives you the one that matches id. 

Original comment by inder123 on 8 Jan 2010 at 7:03

GoogleCodeExporter commented 9 years ago
The problem with b) it that i cannot access id and other fields from JSON data 
in InstanceCreator

Original comment by zlow...@gmail.com on 8 Jan 2010 at 7:11

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 7 Oct 2010 at 7:21

GoogleCodeExporter commented 9 years ago

Original comment by inder123 on 3 Nov 2010 at 1:48

GoogleCodeExporter commented 9 years ago
I don't think we'll ever build this in. Users can accomplish this with their 
own TypeAdapterFactory instances.

Original comment by limpbizkit on 30 Dec 2011 at 6:39