This utility is useful to generate user friendly message from user objects and object
arrays. The object array can be nested deep to any number of levels.
public static final String DEFAULT_ITEM_SEP = ","; public static final String NULL = "<null>"; public static final String EMPTY = "<empty>";
/**
* This method returns Object [] in String format.
* This handles all Objects
*/ public static String getAsString(Object objOrObjAry) {
/**
* Comma is default separator.
*/ return getAsString(objOrObjAry, DEFAULT_ITEM_SEP);
}/* end of getAsString method */
/**
* This method returns Object [] in String format.
* This handles all Objects
*/ public static String getAsString(Object objOrObjAry, String separator) {
try { return getString(objOrObjAry, separator);
} catch ( Exception e ) {
/**
* Incase of any unexpected errors return generic
* String representation of that Object.
*/ return objOrObjAry.toString();
}/* end of try catch block */
}/* end of getAsString method */
/**
* This method returns String representation of any object.
* It recursively converts all arrays in the given object to string
* until there are no more arrays.
*
*/ private static String getString(Object objOrObjAry, String separator) {
if ( objOrObjAry == null) { return NULL;
}
/**
* Check (Object/primitive)[] or not.
*/ if (objOrObjAry.getClass().isArray()) {