GithubHelp home page GithubHelp logo

Comments (7)

cpovirk avatar cpovirk commented on May 28, 2024 1

Reflection is definitely sometimes a quick way to get things working. However, since it depends on the implementation details of the library you're reflecting on, it often leads to breakages down the line. (For example, it's usually one of the main obstacles to JDK upgrades.) So the convenience and compatibility today may lead to inconvenience and incompatibility later on.

from guava.

cpovirk avatar cpovirk commented on May 28, 2024

Since GsonSerializer is creating the Range object, you'll have to identify who is responsible for that code and figure out how it's serializing and deserializing the new range. GsonSerializer isn't part of Guava, so we don't have control over that.

from guava.

YongwuHe avatar YongwuHe commented on May 28, 2024

Since GsonSerializer is creating the Range object, you'll have to identify who is responsible for that code and figure out how it's serializing and deserializing the new range. GsonSerializer isn't part of Guava, so we don't have control over that.

ex:
public boolean hasLowerBound() { return lowerBound != Cut.belowAll(); }
When the lowerBound object is deserialized, although it is still of type com.google.common.collect.Cut.BelowAll, since it is a re-created object, it will not be equal to Cut.belowAll(). So I think this judgment is not accurate enough. Would it be more accurate to use the following judgment?
public boolean hasLowerBound() { return ! (lowerBound instanceof BelowAll) ; }
@cpovirk

from guava.

cpovirk avatar cpovirk commented on May 28, 2024

If GsonSerializer is creating extra instances of private classes by using reflection to override visibility rules, then your suggestion would probably fix the problem you're seeing. But that is an approach that I would not want to encourage: Such reflection may cause many other such problems, and I don't want to give users false hope that it will work in general or that we're doing any kind of testing or planning to make that happen.

from guava.

YongwuHe avatar YongwuHe commented on May 28, 2024

If I need to pass the Range type when requesting the external interface, I first need to serialize the Range into JSON and send it to the server. Upon receiving the JSON, the server needs to deserialize it to obtain the correct Range type and perform the corresponding logical processing. However, this scenario becomes impractical because the deserialization process requires the object to be regenerated
@cpovirk

from guava.

cpovirk avatar cpovirk commented on May 28, 2024

It sounds like GsonSerializer needs to serialize and deserialize a Range object manually instead of using reflection. That probably means that it will need to change to use a custom serializer for Range.

from guava.

YongwuHe avatar YongwuHe commented on May 28, 2024

This workaround may necessitate extra effort from the user. I think as a tool class, it is crucial to consider its convenience for users across different scenarios and its compatibility with various use cases.

from guava.

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.