I have a concatenated
String separated by a delimiter. Am planning to develop a generic method. Say for example, I have 2 different classes [class A and class B] as follows:
Say now I’ve 2 lists of objects, list<A> and list<B>, By using ‘#’ as delimiter and ‘,’ as a sub delimiter I have strings like:
String a = 11,abc,05/29/2012,11.12#12,xyz,05/29/2012,12.11 --> serialized from list<A>
String b = 12,x#11,y#1112,z --> serialized from list<B>
And I want to have a method where It takes this serialized string as an argument and returns me the same List of appropriate class.
The method am planning to develop has the following signature:
Public static List<?> deserailizeList(Class className, String serializedStr, String delim, String subDelim) {
//here am making use of reflection API , any better options we may go?
}
Now if I pass className as ‘A’ and serializedStr as the serialized String as mentioned above ‘a’ , now I want the method to return the list<A> by deserializing the string. And the same for Class B.
While developing I got stuck in how to set the values to appropriate datamembers. Need some assistance.