public class WorkSheetJSONDeserializer implements IDeserializer {
public static transient Logger logger = Logger.getLogger(WorkSheetJSONDeserializer.class);
public WorkSheetDefinition deserialize(Object o) throws SerializationException {
WorkSheetDefinition workSheetDefinition = null;
JSONObject workSheetDefinitionJSON = null;
logger.debug("IN");
try {
Assert.assertNotNull(o, "Object to be deserialized cannot be null");
if(o instanceof String) {
logger.debug("Deserializing string [" + (String)o + "]");
try {
workSheetDefinitionJSON = new JSONObject( (String)o );
} catch(Throwable t) {
logger.debug("Object to be deserialized must be string encoding a JSON object");
throw new SerializationException("An error occurred while deserializing query: " + (String)o, t);
}
} else if(o instanceof JSONObject) {
workSheetDefinitionJSON = (JSONObject)o;
} else {
Assert.assertUnreachable("Object to be deserialized must be of type string or of type JSONObject, not of type [" + o.getClass().getName() + "]");
}
workSheetDefinition = new WorkSheetDefinition();
try {
deserializeSheets(workSheetDefinitionJSON, workSheetDefinition);
} catch (Exception e) {
throw new SerializationException("An error occurred while deserializing worksheet: " + workSheetDefinitionJSON.toString(), e);