I'd like to write a Java program that takes arbitrary data and stores it in a MySQL database. The data can later be read again and the original object structure is reconstructed.
The background is that I want a generic tool for forms that need email verification in order to complete. So:
- User fills in form,
- Data is stored as mentioned above,
- Email is sent to the user with a link containing a certain UUID identifying the data set,
- User clicks the link,
- The servlet loads the stored data using the UUID in the link and processes the data.
I'd like this to work for any data, not only String/String or String/int pairs. I was thinking about using a LazyDynaBean from org.apache.common.beanutils as a means to pass data to my tool.
The question is: is there a nice way to serialize that stuff, even when the values are beans (let's restrict on Java Beans), and not only primitives?
I was thinking that my database tables could look like this
emailVerification
| ID | UUID | validUntil |
emailVerificationData
| ID | emailVerification.ID | name | index | key | value | className |
Is that feasable at all? Could anyone point me into the right direction on how to store and load a DynaBean into this structure? Or any alternatives that I've missed?
Thanks a bunch.
You could serialize-/deserialize your Beans to and from XML (s.example below) and store the String in the database.
Does this help?