[Simple-support] How do you serialize an object as an attribute?
Brought to you by:
niallg
|
From: James O. <Jam...@ip...> - 2011-09-06 22:29:23
|
Let's say I have an object (ID). ID: - Number - Version This can be easily expressed as a simple string in the format <number>-<version> e.g. 1234-1 In most cases I'd like to express this as an attribute for other xml elements (id="1234-1") However, it's currently in element format. e.g. <ID number="1234" version="1"> How do I get this annotated to read into and out of another object's element's attribute? e.g. <someOtherObject attribute1="blah blah" id="1234-1"/> To make this request more complicated, let's say I want to preserve some backwards compatibility and be able to deserialize the old element based XML, how would I do that? Can I serialize the ID as an element in some cases where it is specified as an @Element in one including object or as an attribute in another including object where it is annotated as @Attribute there? Thanks! |