Adding serialization code to a POJO using XDoclet?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Terry_S
Posted On:   Thursday, March 30, 2006 07:21 PM

Hi, I've been Googling in the hopes of finding an example that can solve my problem. I have a POJO class defined and would like to generate some customized serialization code based on some field level marker tags. For example, my POJO class is as follows: public class AnObject { /** * @serialize */ int anInt; /** * @serialize */ String aString; boolean aBool; } From the above source, I'd like to generate the corresponding Java source which includes serialization code (writeObject and readObject methods) for those fields with a @serialize marker tag. What I'd like to see is as follows:    More>>

Hi,


I've been Googling in the hopes of finding an example that can solve my problem. I have a POJO class defined and would like to generate some customized serialization code based on some field level marker tags. For example, my POJO class is as follows:


			
public class AnObject
{
/**
* @serialize
*/
int anInt;

/**
* @serialize
*/
String aString;

boolean aBool;
}



From the above source, I'd like to generate the corresponding Java source which includes serialization code (writeObject and readObject methods) for those fields with a @serialize marker tag. What I'd like to see is as follows:


			
public class AnObject
{
/**
* @serialize
*/
int anInt;

/**
* @serialize
*/
String aString;

boolean aBool;

/**
* Generated from XDoclet
*/
private void writeObject(java.io.ObjectOutputStream out)
throws IOException
{
out.writeInt(anInt);
out.writeObject(aString);
}

private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException
{
this.anInt = in.readInt();
this.aString = (String)in.readObject();
}
}


I've defined an XDoclet template to generate the serialization code, but I've been unable to figure out a way using XDoclet to, effectively, append this serialization code to the POJO definition and spit out the final result. Any leads is greatly appreciated!

   <<Less
About | Sitemap | Contact