I need to serialise a javabean (with arbitrary nested beans) to plain text, and then later restore as an Object graph.
For the purposes of this question I am not interested in XML, JSON, etc. but rather name/value pairs.
The Spring DataBinder is great for turning a list of name/value pairs into a real Object. For example we can supply:
values.addPropertyValue("id", "6789");
values.addPropertyValue("nestedBean[0].systemId", "FOO");
values.addPropertyValue("nestedBean[1].systemId", "BAR");
And use the DataBinder to produce a top level bean (with property id
) containing a List
of two nested beans.
My question is, how can I easily serialise a bean into the format that DataBinder expects?
I would expect something of the form:
Map<String,String> reduceBeanToNameValuePairs(Object bean)
but have had no luck finding anything of the sort.