Closed cbedoya closed 6 years ago
Hello
I would suggest you implement a TypeAdapterFactory. This factory creates a type adapter that would check if the object being deserialized is already cached, and if not will use the original type adapter to deserialize it from json into an object and then cache it.
You need to be careful with memory usage, so your pool of objects needs to be composed of weak references or self clean after a while.
Was my suggestion useful for you?
Thanks
I have an issue with the Gson library, and I found your library, which looks that can suit almost all my needs, except for this one, the possibility to reuse already parsed objects, for example, lets say you have this json:
This is a very basic example, there are 3 students who assist to 0 or many classes. As you can see 2 or more students can have the same reference to an specific subject, but when I parse the object, Student 1 will have an object for subject 1, Student 2 will have a different object but with same information as the one for Student 1, so my question basically is, can this be achieved using the post-processors you have?
In theory what comes to mind is that before creating an object instance, there should be some kind of pool, so I look using the id and type, if I find the object I return it, otherwise I let the parser to create the instance for me. Do you have something for that case? Looks like its something between the Preprocessor and the Post-processor where you generate the actual Class.
I will appreciate any help or thoughts on this.