Git Product home page Git Product logo

Comments (5)

johncarl81 avatar johncarl81 commented on August 10, 2024

The CREATOR object instance will be located in the generated code:

@Parcel
public class Example {
    String value;
}

Generated:

public class Example$$Parcelable implements Parcelable, ParcelWrapper<Example> {

    private Example example$$0;
    @SuppressWarnings("UnusedDeclaration")
    public final static Example$$Parcelable.Creator$$0 CREATOR = new Example$$Parcelable.Creator$$0();
    ...

    private final static class Creator$$0 implements Creator<Example$$Parcelable>  {
        ...
    }
}

Why do you need to access it?

from parceler.

mg6maciej avatar mg6maciej commented on August 10, 2024

To call createFromParcel on it. Thanks.

from parceler.

johncarl81 avatar johncarl81 commented on August 10, 2024

You really shouldn't have to reference the CREATOR object. What's your use case?

A couple of options instead of referencing the CREATOR directly. You can reference the generated code's constructor:

Parcelable parcelable = new Example$$Parcelable(parcel);

or the Parcels utility class:

savedInstanceState.putParcelable("parcel", Parcles.wrap(input));
...
Object original = Parcels.unwrap(parcel.getParcelable("parcel"));

from parceler.

mg6maciej avatar mg6maciej commented on August 10, 2024

There are APIs that require Parcelable.Creator interface, e.g. Parcel.createTypedArrayList. I don't think there is anything wrong with using CREATOR direcly.

from parceler.

johncarl81 avatar johncarl81 commented on August 10, 2024

Certainly nothing wrong with using the CREATOR directly, but one goal of Parceler is to not have to reference the generated code.

Parceler does handle List<@Parcel>'s (#18) if you don't want to manage the serialization/deserialization of parcelable lists manually:

@Parcel class Example{}

List<Example> exampleList = new ArrayList<Example>();
exampleList.add(new Examle());
Parcelable wrapped = Parcels.wrap(exampleList);
savedInstanceState.putParcelable("examplelist", wrapped);
...
List<Example> unwrapped = Parcels.unwrap(parcel.getParcelable("examplelist"));

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.