0

I wrote this Java parser library which outputs a set of POJO classes:

  • Offer
  • Room
  • Stream
  • Url
  • VideoSize

Since I want to use the parsed data in an Android project I am running into a problem: the model classes are not parcelable nor serializable. The latter could be implemented via java.io.Serializable. Is there a way to implement Parcelable without copying all fields into new models?

JJD
  • 50,076
  • 60
  • 203
  • 339

1 Answers1

0

You don't need new models. You would need to have each model you need serialized to implement Parcelable and to write themselves to the parcel so they can be serialized and deserialized. I'm assuming you're trying to pass one of these across activities/servies- in that case you'll need to be able to serialize the model with one of those two methods.

If you aren't trying to send them between activities/services I'd wonder why the fact they aren't parelable or serializable matters.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • Your assumption is correct - I want to send it between activities/fragments. But you are missing that the model comes from a Java library. `Parcelable` is from the Android world. – JJD Dec 17 '15 at 01:15
  • Then you're kind of screwed. The reason there's no generic way to implement something as parcelable is that there's no generic way to know what data in a class to carry over- just a blind copy of all the fields of an object may be too much or not enough. There's no way to know unless you wrote the class if you need a shallow or deep copy, or if fields aren't needed/shouldn't be copied. You could try extending an object and having the child class be a parcelable if it has access to enough state, but you aren't getting by without a second class of some sort. – Gabe Sechan Dec 17 '15 at 01:22