[android-developers] Re: Serializable subclass of non-serializable class

2011-10-07 Thread Lew
'Serializable' is ill-suited for persistence to disk.  'Parcelable' isn't 
much better.  They're intended for in-process or inter-process transfers of 
data, not persistence.  Don't use them.  

'Serializable', in particular, imposes a huge maintenance burden, in that it 
locks down implementation of the class /ad aeternam/.  Read Joshua Bloch's 
entire chapter on serialization in /Effective Java/ for the relevant 
warnings, dangers and gotchas.  There are many.  Really.  Make sure you 
really know what you're doing before using 'Serializable'.

That said, the methods that support serialization can work around your 
trouble, potentially.  You sort of hand-roll the parts not provided upstream 
for you by the API.
http://download.oracle.com/javase/7/docs/api/java/io/Serializable.html

Don't walk into serialization without doing your homework first.  Lesson 
one: it isn't good for persistence.  Lesson two: it isn't cheap.  Or maybe 
it's the other way around.

-- 
Lew

On Wednesday, October 5, 2011 8:20:52 AM UTC-7, Jean-Michel wrote:

 No, I am serialising to disk. 

 Do you think it could work out? 

 Any idea how to use Parcelable ? 

 Many thanks, 
 Jean-Michel 

 On 5 oct, 16:43, Daniel Drozdzewski daniel.dr...@gmail.com 
 wrote: 

  Now luckily for you, Location in Android implements Parcelable 
  interface, which could be of help, depending where are you sending to 
  and receiveing from your Leg/Location related data. 
  If it is within the same machine between a service and an activity, 
  then you are fine.  If you are passing it via network, you need to 
  implement a DTO, that implements Serializeable and holds all the 
  necessary data that you depend on. You then pass that DTO and with its 
  help you create new Location object at the receiving end. 
  
  HTH 
  
  -- 
  Daniel Drozdzewski

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: Serializable subclass of non-serializable class

2011-10-06 Thread Daniel Drozdzewski
JM,

sorry I missed your reply among 100s of emails yesterday...

On 5 October 2011 17:18, Jean-Michel jeanmichel.caz...@gmail.com wrote:
 Daniel, sorry to be a pain in the bum, but there are still 2 things I
 cannot figure out.

 First I am not sure what you mean by DTO, but from what I understand
 it is basicaly a place holder for the data in my non-serilizable
 class.
 I understand how to transfer dta (the one I care about) between
 LocationDTO and Location.

It is not a place holder. It is actual data holder and Location is left alone.

You do the following:

1. Define LocationDTO that implements Serializable, which will store
all data that you need from Location.
2. When you are about to persist your Location to storage, you
populate that DTO with the latest values from Location.
3. You serialize DTO and persist resulting stream.
application is OFF here
4. Upon re-launch of your application, you read the serialized DTO
from the storage, therefore de-serializing the DTO.
5. Create brand new Location (Location loc = new Location()) and
populate all its properties from deserialized DTO.

As you can see, you have not serialized or deserialized Location class
(or any of its subclasses) at all, therefore avoiding all the troubles
that you have with it.


-- 
Daniel Drozdzewski

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Serializable subclass of non-serializable class

2011-10-05 Thread Jean-Michel
No, I am serialising to disk.

Do you think it could work out?

Any idea how to use Parcelable ?

Many thanks,
Jean-Michel

On 5 oct, 16:43, Daniel Drozdzewski daniel.drozdzew...@gmail.com
wrote:

 Now luckily for you, Location in Android implements Parcelable
 interface, which could be of help, depending where are you sending to
 and receiveing from your Leg/Location related data.
 If it is within the same machine between a service and an activity,
 then you are fine.  If you are passing it via network, you need to
 implement a DTO, that implements Serializeable and holds all the
 necessary data that you depend on. You then pass that DTO and with its
 help you create new Location object at the receiving end.

 HTH

 --
 Daniel Drozdzewski

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Serializable subclass of non-serializable class

2011-10-05 Thread Daniel Drozdzewski
On 5 October 2011 16:20, Jean-Michel jeanmichel.caz...@gmail.com wrote:
 No, I am serialising to disk.

 Do you think it could work out?

 Any idea how to use Parcelable ?

 Many thanks,
 Jean-Michel


Jean-Michel,

Parcelable is used for inter-process communication and is designed
specifically for that (i.e. passing the data between services and
activities).

In order to save it to disk, you have to create mentioned DTO.

It can sound serious, but it is simple:

class LocationDTO implements Serializable {

//all properties extracted from Location that you need
//... with all getters and setters.

}

When you need to preserve the location, you create this DTO, populate
all properties yourDTO.setAcuracy(yourLocation.getAcuracy());

... and preserve this DTO. Then when you need it back in memory, you
deserialise this DTO, create new Location object and populate its
properties from DTO.

-- 
Daniel Drozdzewski

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Serializable subclass of non-serializable class

2011-10-05 Thread Jean-Michel
Daniel, sorry to be a pain in the bum, but there are still 2 things I
cannot figure out.

First I am not sure what you mean by DTO, but from what I understand
it is basicaly a place holder for the data in my non-serilizable
class.
I understand how to transfer dta (the one I care about) between
LocationDTO and Location.

Then, how am I stopping the default process to try to serialize the
Location parent object. At thye moment I am doing nothing, this is all
happening by default.

If you would have a link on some doc or an example that would greato-
smashing-fantastic ;).

JM

On 5 oct, 17:41, Daniel Drozdzewski daniel.drozdzew...@gmail.com
wrote:
 On 5 October 2011 16:20, Jean-Michel jeanmichel.caz...@gmail.com wrote:

  No, I am serialising to disk.

  Do you think it could work out?

  Any idea how to use Parcelable ?

  Many thanks,
  Jean-Michel

 Jean-Michel,

 Parcelable is used for inter-process communication and is designed
 specifically for that (i.e. passing the data between services and
 activities).

 In order to save it to disk, you have to create mentioned DTO.

 It can sound serious, but it is simple:

 class LocationDTO implements Serializable {

 //all properties extracted from Location that you need
 //... with all getters and setters.

 }

 When you need to preserve the location, you create this DTO, populate
 all properties yourDTO.setAcuracy(yourLocation.getAcuracy());

 ... and preserve this DTO. Then when you need it back in memory, you
 deserialise this DTO, create new Location object and populate its
 properties from DTO.

 --
 Daniel Drozdzewski

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en