Comments (7)
@interappcci, @lalpert I think I will include my suggestion in my previous comment since it solves also a different requirement that was raised to me the other day.
Does that work for both of you in regards to the circular reference problem?
from gson-fire.
Thanks for your suggestion, I will try to include this or something similar in 1.8.0 which I will be released around mid-oct.
from gson-fire.
Any progress with this issue? Is there some solution to handle cyclic reference and avoid stack overflow (other than remove one side of bidirectional reference)?
Thanks!
from gson-fire.
Is there some update about that?
I've been looking for a elegant solution to this since ever and nothing found.
For while..
from gson-fire.
Sorry I've been super busy and lost track of this. I'll think about something based on what @lalpert suggested and will reply back here before the end of the week with a timeline.
from gson-fire.
Would it work if I create an annotation to override the type adapter of a particular field in a class? For example
public class Person {
private int id;
private String name;
private House house;
}
public class House {
@TypeAdapter(SimplePersonAdapter.class)
private Person owner;
}
public class SimplePersonAdapter implements TypeAdapter<Person> {
//this class just serializes a simplified version of a Person object, for example it could just serialize the id
}
from gson-fire.
I just need to cxclude a field at the second nested while serializing a object:
class User {
String name;
User createdBy;
}
class JsonRespWrap<D> {
int code;
User data;
public JsonRespWrap (D data ) {
this.data = data
this.code = 0
}
}
User user = userDao.findOne(1)
gson.toJson(new JsonRespWrap(user)); // data.createdBy.createdBy should be excluded but data.createdBy should be included
// here is the exclusion stratety
public class GsonExclusionStrategy implements ExclusionStrategy{
//...
@Override
public boolean shouldSkipClass(Class<?> clazz) {
return true;
}
@Override
public boolean shouldSkipField(FieldAttributes f) {
//how to do whthout parent FieldAttributes (or a stack of FieldAttributeses) provided as parameter
}
}
from gson-fire.
Related Issues (20)
- Reuse Exclusion Strategies HOT 11
- Add more powerful wrapping/unwrapping HOT 1
- Reuse Objects HOT 2
- Hooks Exception is not forwarded. HOT 2
- TypeAdapter does not respect `lenient` value HOT 3
- Custom deserialization without deserializer/type adapter? HOT 3
- Custom Deserialization of same field based on it's type
- Preprocessor for Array Insertion HOT 6
- Can't serialize NaN HOT 11
- RFC3339 Parser is wrong HOT 2
- Serialize complex map keys to strings and back HOT 2
- Add OSGi Support HOT 10
- Inconsistent licensing information
- Missing Releases on Github HOT 1
- Check for required fields HOT 1
- Unresolved requirement: Import-Package: com.google.gson.internal.bind HOT 2
- No release tags for versions 1.8.4 and 1.8.5?
- How to exclude a field from serialization?
- update gson from 2.8.6 to version com.google.code.gson:gson:2.8.9 HOT 1
- osgi is not more compatible with new version of gson HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gson-fire.