Giter VIP home page Giter VIP logo

Comments (7)

julman99 avatar julman99 commented on July 18, 2024 1

@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.

julman99 avatar julman99 commented on July 18, 2024

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.

Typografikon avatar Typografikon commented on July 18, 2024

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.

interappcci avatar interappcci commented on July 18, 2024

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.

julman99 avatar julman99 commented on July 18, 2024

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.

julman99 avatar julman99 commented on July 18, 2024

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.

aninfeel avatar aninfeel commented on July 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.