Git Product home page Git Product logo

Comments (6)

johncarl81 avatar johncarl81 commented on August 10, 2024 1

Ah, this is happening because the Parcelable isn't actually going through a serialization/deserialization cycle. If you're running this on your desktop I've put together a testing utility that forces this cycle to take place here: ParcelsTestUtil. Here's a passing test if you want to try it out:

@RunWith(RobolectricTestRunner.class)
@Config(manifest=Config.NONE)
public class TestPolymorphism {

    @Parcel
    public static class Example {
        public Parent p;
        @ParcelConstructor Example(Parent p) { this.p = p; }
    }

    @Parcel public static class Parent {}
    @Parcel public static class Child extends Parent {}

    @Test
    public void testStuff() {
        Example example = new Example(new Child());
        assertTrue(example.p instanceof Child);
        example = Parcels.unwrap(ParcelsTestUtil.wrap(example));
        assertFalse(example.p instanceof Child);
    }
}

from parceler.

WildOrangutan avatar WildOrangutan commented on August 10, 2024

Ok, I've done some experiments to figure how it actually behaves.

Looks like there is some instance caching going on, and documentation does not mention that.

Anyone else wondering... output of example from documentation is correct, when app process is re-created.
If only simple rotation occurs, object instance stays the same, hence my original post results hold.

Don't know to what extent I like instance caching tough. Could be bug prone on mutable objects.

from parceler.

johncarl81 avatar johncarl81 commented on August 10, 2024

Hmm, could you show an example of what you mean? We do have some caching, but it's meant for bidirectional object relationships.

from parceler.

WildOrangutan avatar WildOrangutan commented on August 10, 2024

As far as the first post goes, I've been trying out same example from documentation. I've just added reference checking, like so:

Example in = new Example(new Child());
System.out.println(in.p instanceof Child); // true

Example out = Parcels.unwrap(Parcels.wrap(in));
System.out.println(out.p instanceof Child); // true

System.out.println(out == in); // true

For the second post, the project I'm working on has mislead me. Not sure why atm. I can't reproduce it elsewhere, sorry about that. I'll cross-out sentences above, that are probably incorrect.

from parceler.

WildOrangutan avatar WildOrangutan commented on August 10, 2024

I see. Thanks for explanation.

from parceler.

johncarl81 avatar johncarl81 commented on August 10, 2024

Maybe the docs could be more explicit about this. They are fork friendly btw.

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.