Search code examples
javaandroidparcelable

How to implement Parcelable for an Arraylist of Object which does not implement parcelable?


I have a class which is in a Jar file, and it does not implement parcelable and I cannot edit the Jar file. I get the object as a response from the server and I need to pass it to the next activity using parcelable, This class also has other Class objects. How can I achieve this ?

Here is the code of the class :

//The class whose Arraylist I want to send to another activity. //This class is inside JAR

public class MacroConfig implements IConfig, IData {
    private MacroIdentifiers identifiers;
    private ArrayList<MacroRel> relation;
    private ExecutionMode executionMode;
    private ArrayList<RuleConfig> ruleConfig;
    private ArrayList<String> instruction;
    private ArrayList<String> _type_id;
    private String type;
    @JsonAdapter(JsonConverter.class)
    private ArrayList<Extension> extension;
    @JsonAdapter(JsonConverter.class)
    private Expansion expand;

    public MacroConfig() {
    }

I tried things mentioned on blogs and other Stackoverflow questions but didn't find any proper solution to it.


Solution

  • May be u can try this alternate way, From sender Activity:

    intent.putExtra("myObject",new Gson().toJson(listObject));
    

    in oncreate of receiver activity

    List<MyObject> obj = new Gson().fromJson(getIntent().getExtras().getString("myObject"), new TypeToken<List<MyObject>>(){}.getType());