views:

446

answers:

2

I know that Serialization (Serializable) is not available in the Micro Edition of Java. It's kinda straight forward to save primitives like int and java.lang.String objects with the RMS. But if I want to save (make persistant) an arbitrary object? Is that possible?

A: 

Unfortunately there's no way to save an arbitrary object without writing code for it, since reflection is severely limited in J2ME (you can look up classes, but can't look up their fields and methods).

Joachim Sauer
hm, ok. I think froggy fixed that ;)
Schildmeijer
sorry, i mean floggy
Schildmeijer
Nice, but it seems to use byte-code generation to get around the lack of reflection, so my answer still kind-of stands.
Joachim Sauer
+5  A: 

You can use the Connection API to write the data to a File/Stream. Please keep in mind that it is easy to persist the data in to a Stream but inorder to restore the data from the Stream you will have to write your own code. Usually reflection is used for this purpose and it becomes a bottle neck on many devices.

So instead of re-inventing the wheel I would advise using Floggy (http://floggy.sourceforge.net/). Floggy is a free object persistence framework for J2ME/MIDP applications. The main goal of this framework is to abstract the data persistence details from the developer, reducing the development and maintenance effort. You can check the examples at http://floggy.sourceforge.net/getting-started.html#framework

aha, floggy is truly what I was looking for.
Schildmeijer