Git Product home page Git Product logo

Comments (19)

johncarl81 avatar johncarl81 commented on August 10, 2024

Hmm, could you just make that @Transient? Finals should possibly error in field serialization during code generation. Or maybe finals are ignored and a warning is given.

from parceler.

vinc3m1 avatar vinc3m1 commented on August 10, 2024

Ah, just noticed @Transient, but static final vars should probably just be assumed transient no?

from parceler.

johncarl81 avatar johncarl81 commented on August 10, 2024

I'm thinking all finals should be ignored, not only static final.

from parceler.

vinc3m1 avatar vinc3m1 commented on August 10, 2024

probably for simplicity. Gson deserializes final fields through reflection, but I really don't think supporting that use case is necessary.

from parceler.

johncarl81 avatar johncarl81 commented on August 10, 2024

I guess we could serialize finals using reflection (we use reflection for private fields serialization). I wonder if this is necessary though, since we require a zero-arg constructor and finals need to be set in constructor blocks.

from parceler.

vinc3m1 avatar vinc3m1 commented on August 10, 2024

I would skip all finals for now and maybe add support in a later version if needed

from parceler.

johncarl81 avatar johncarl81 commented on August 10, 2024

Implemented the final fields set by reflection case (and a couple of other edge cases), let me know how it works for you @vinc3m1: 48fb1e1

from parceler.

vinc3m1 avatar vinc3m1 commented on August 10, 2024

I get these warnings during compilation, but i'm not seeing any crashes (yet).

warning: Parceler: Reflection is required to modify private fields, consider using non-private.
    public static final String STATUS_OFFLINE = "offline";

are static final fields actually ignored? or will parceler actually try to change them? More informative warning messages would be nice.

from parceler.

johncarl81 avatar johncarl81 commented on August 10, 2024

Parceler will try to read from and write to them. Reading from them isn't the issue, it's the writing that causes Parceler to require reflection. It seems like there are cases that writing finals doesn't work, even with reflection because of compiler inlining.

from parceler.

vinc3m1 avatar vinc3m1 commented on August 10, 2024

I think specifically static finals should always be ignored, they're usually compiled to constant values.

from parceler.

johncarl81 avatar johncarl81 commented on August 10, 2024

Im trying to think about this from a serialization perspective, much like Gson or regular Java serialization. In those cases I believe static finals are serialized, mainly because they could be reloaded by a separate VM. In Parceler's case, I don't believe Parcelables are serialized between Virtual Machines. Maybe this means all statics should be ignored.

Also, the transient keyword is respected in serialization cases, maybe we should support that as an analogous option to @Transient.

I believe regular finals should be serialized / deserialized properly, even if they do require reflection. This is inline with the serialization perspective.

Maybe I'm talking myself into this solution...

So here's my thoughts to go forward with:

  • ignore all static fields because Parcelables are only serialized within the same VM (need to verify this)
  • add transient keyword analogy to @Transient

from parceler.

vinc3m1 avatar vinc3m1 commented on August 10, 2024

I'm positive that Parcelables are mean't to be serialized within the same device, but not necessary the same process. I can't find the source but I remember a core android dev saying something along those lines. It was designed more for passing messages around and persisting state locally, not for long term storage like serializable or json. Thus why there isn't a serialVersionUID equivalent. And why Parcelables should never be saved to disk because implementation may change with dfiferent versions of Android.

It is however possible to pass Parcelables around between different apps via intents and bundles. I guess in that case, there is a possibility that you would want to marshall a constant, so maybe the @Transient annotation is sufficient

from parceler.

johncarl81 avatar johncarl81 commented on August 10, 2024

Right, good points. In that case maybe we shouldn't ignore statics, unless they are @Transient or transient of course. I'm going to set up a quick test app to verify, but I would imagine you are correct, that statics will not be identical between processes (or classloaders?).

I'm still interested in adding the transient keyword for completeness.. and possibly update the warning to cover final variables as well.

from parceler.

johncarl81 avatar johncarl81 commented on August 10, 2024

Ok, transients are now respected and I altered the warning to handle finals/privates accordingly f15512e. you could define your static final variable as follows:

public transient static final String STATUS_OFFLINE = "offline";

don't forget to run with ./gradlew build --refresh=dependencies

from parceler.

johncarl81 avatar johncarl81 commented on August 10, 2024

@vinc3m1 would love to release this afternoon, let me know if this works for you and I'll do it.

from parceler.

vinc3m1 avatar vinc3m1 commented on August 10, 2024

Yeah assuming this doesn't break anything. I think I'll stick to using @Transient so this doesn't affect me much.

from parceler.

johncarl81 avatar johncarl81 commented on August 10, 2024

Cool, sounds good. I'll release then.
On Feb 26, 2014 1:58 PM, "Vince Mi" [email protected] wrote:

Yeah assuming this doesn't break anything. I think I'll stick to using
@transient so this doesn't affect me much.

Reply to this email directly or view it on GitHubhttps://github.com//issues/21#issuecomment-36175635
.

from parceler.

johncarl81 avatar johncarl81 commented on August 10, 2024

Just released under 0.2.7.

from parceler.

vinc3m1 avatar vinc3m1 commented on August 10, 2024

👍

from parceler.

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.