List of usage examples for java.lang Class isEnum
public boolean isEnum()
From source file:org.broadinstitute.gatk.utils.help.GenericDocumentationHandler.java
/** * Attempt to instantiate class c, if possible. Returns null if this proves impossible. * * @param c/*from ww w.j a v a2 s .co m*/ * @return */ private Object makeInstanceIfPossible(Class c) { Object instance = null; try { // don't try to make something where we will obviously fail if (!c.isEnum() && !c.isAnnotation() && !c.isAnonymousClass() && !c.isArray() && !c.isPrimitive() & JVMUtils.isConcrete(c)) { instance = c.newInstance(); //System.out.printf("Created object of class %s => %s%n", c, instance); return instance; } else return null; } catch (IllegalAccessException e) { } catch (InstantiationException e) { } catch (ExceptionInInitializerError e) { } catch (SecurityException e) { } // this last one is super dangerous, but some of these methods catch ClassNotFoundExceptions // and rethrow then as RuntimeExceptions catch (RuntimeException e) { } return instance; }
From source file:com.tongbanjie.tarzan.rpc.protocol.RpcCommand.java
private void customHeaderToMap() throws RpcCommandException { if (this.customHeader != null) { Field[] fields = getClazzFields(customHeader.getClass()); if (null == this.customFields) { this.customFields = new HashMap<String, String>(8); }//from w w w . j a v a 2s . c o m for (Field field : fields) { String fieldName = field.getName(); Class clazz = field.getType(); if (Modifier.isStatic(field.getModifiers()) || fieldName.startsWith("this")) { continue; } Object value; try { field.setAccessible(true); value = field.get(this.customHeader); } catch (Exception e) { throw new RpcCommandException( "Encode the header failed, get the value of field <" + fieldName + "> error.", e); } if (value == null) { continue; } if (clazz.isEnum()) { this.customFields.put(fieldName, value.toString()); } else { String type = getCanonicalName(clazz); String strValue = ClassUtils.simpleValueToString(type, value); if (strValue == null) { throw new RpcCommandException("Encode the header failed, the field <" + fieldName + "> type <" + getCanonicalName(clazz) + "> is not supported."); } this.customFields.put(fieldName, strValue); } } } }
From source file:org.openmainframe.ade.impl.PropertyAnnotation.java
@SuppressWarnings({ "unchecked" }) static private void setProps(Object obj, Map<String, ? extends Object> props, Pattern filter, boolean safe) throws MissingPropertyException, IllegalArgumentException { final Class<?> annotatedClass = obj.getClass(); final Set<String> keyset = new TreeSet<String>(props.keySet()); for (Field field : annotatedClass.getDeclaredFields()) { final Property annos = field.getAnnotation(Property.class); if (annos != null) { // skip missing and non-required properties final String key = annos.key(); if (!props.containsKey(key)) { if (annos.required()) { throw new MissingPropertyException("Missing property: " + key); } else { // no value for non-required property continue; }/*from ww w . ja v a 2 s . co m*/ } final Class<? extends IPropertyFactory<?>> factoryClass = annos.factory(); final Object rawVal = props.get(key); final Type fieldType = field.getGenericType(); Object val = null; if (factoryClass != Property.NULL_PROPERTY_FACTORY.class) { // check if this factory is eligible for creating this property final Type factoryProductType = resolveActualTypeArgs(factoryClass, IPropertyFactory.class)[0]; if (!TypeUtils.isAssignable(factoryProductType, fieldType)) { throw new IllegalArgumentException("The factory provided for the field: " + field.getName() + " is not compatible for creating object of type: " + fieldType); } Constructor<? extends IPropertyFactory<?>> constructor; try { constructor = factoryClass.getConstructor(); } catch (Exception e) { throw new IllegalArgumentException( "Missing empty constructor in: " + factoryClass.getName(), e); } IPropertyFactory<?> factory; try { factory = constructor.newInstance(); } catch (Exception e) { throw new IllegalArgumentException("Failed instantiating: " + factoryClass.getName(), e); } try { val = factory.create(rawVal); } catch (Exception e) { throw new IllegalArgumentException("Failed extractring property value: " + key, e); } } else if (TypeUtils.isAssignable(rawVal.getClass(), fieldType)) { val = rawVal; } else if (rawVal.getClass().equals(String.class)) { final Class<?> fieldClass = field.getType(); final String stringVal = (String) rawVal; if (fieldClass == Integer.class || fieldClass == int.class) { try { val = Integer.parseInt(stringVal); } catch (Exception e) { throw new IllegalArgumentException("Failed parsing integer value for property: " + key, e); } } else if (fieldClass == Double.class || fieldClass == double.class) { try { val = Double.parseDouble(stringVal); } catch (Exception e) { throw new IllegalArgumentException("Failed parsing double value for property: " + key, e); } } else if (fieldClass == Boolean.class || fieldClass == boolean.class) { try { val = Boolean.parseBoolean(stringVal); } catch (Exception e) { throw new IllegalArgumentException("Failed parsing boolean value for property: " + key, e); } } else if (fieldClass == String.class) { // should never have reached here, since String is assignable from String val = stringVal; } else if (fieldClass.isEnum()) { Class<Enum> fieldEnum; try { fieldEnum = (Class<Enum>) fieldClass; } catch (ClassCastException e) { throw new IllegalArgumentException( "Failed casting to Class<Enum> field class: " + fieldClass.getName(), e); } try { val = Enum.valueOf(fieldEnum, stringVal); } catch (Exception e) { throw new IllegalArgumentException("Failed parsing enum value for property: " + key + "\n\t possible values: " + Arrays.toString(fieldEnum.getEnumConstants()), e); } } else { // try to find String constructor for field, or else throw exception Constructor<?> constructor; try { constructor = fieldClass.getConstructor(String.class); } catch (Exception e) { throw new IllegalArgumentException("Field: " + field.getName() + " of type " + fieldClass + " is not one of the known property type (Integer, Double, Boolean, String, Enum), does not have a String constructor and no custom factory is defined in the annotation!", e); } try { val = constructor.newInstance(stringVal); } catch (Exception e) { throw new IllegalArgumentException("Could not create a new instance for " + field.getName() + " using the String constructor for type: " + fieldClass, e); } } } if (val == null) { throw new IllegalArgumentException("For the key " + key + ", we expect the value to be either assignable to " + fieldType + " or a String"); } try { field.setAccessible(true); field.set(obj, val); keyset.remove(key); } catch (SecurityException e) { throw new SecurityException("Field " + field.getName() + " is not accesible, and could not be set as accesible (probably due to PermissionManager)", e); } catch (Exception e) { throw new IllegalArgumentException( "Failed setting field: " + field.getName() + " with value: " + val, e); } } } if (safe && !keyset.isEmpty()) { throw new IllegalArgumentException("Unrecongnized arguments in the properties: " + keyset.toString()); } }
From source file:eu.sathra.io.IO.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private Object getValue(JSONObject jObj, String param, Class<?> clazz) throws ArrayIndexOutOfBoundsException, IllegalArgumentException, Exception { try {/*from w w w .ja v a2 s . com*/ if (clazz.equals(String.class)) { return jObj.getString(param); } else if (clazz.equals(int.class)) { return jObj.getInt(param); } else if (clazz.equals(long.class)) { return jObj.getLong(param); } else if (clazz.equals(float.class)) { return (float) jObj.getDouble(param); } else if (clazz.equals(double.class)) { return jObj.getDouble(param); } else if (clazz.equals(boolean.class)) { return jObj.getBoolean(param); } else if (mAdapters.containsKey(clazz)) { return mAdapters.get(clazz).load(param, jObj); } else if (clazz.isEnum()) { return Enum.valueOf((Class<? extends Enum>) clazz, jObj.getString(param)); } else if (clazz.isArray()) { return getValue(jObj.getJSONArray(param), clazz.getComponentType()); } else { return load(jObj.getJSONObject(param), clazz); } } catch (JSONException e) { return null; } finally { jObj.remove(param); } }
From source file:io.apiman.manager.api.es.EsMarshallingTest.java
/** * Fabricates a new instance of the given bean type. Uses reflection to figure * out all the fields and assign generated values for each. *//*from w w w. j a va2 s .co m*/ private static <T> T createBean(Class<T> beanClass) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException { T bean = beanClass.newInstance(); Map<String, String> beanProps = BeanUtils.describe(bean); for (String key : beanProps.keySet()) { try { Field declaredField = beanClass.getDeclaredField(key); Class<?> fieldType = declaredField.getType(); if (fieldType == String.class) { BeanUtils.setProperty(bean, key, StringUtils.upperCase(key)); } else if (fieldType == Boolean.class || fieldType == boolean.class) { BeanUtils.setProperty(bean, key, Boolean.TRUE); } else if (fieldType == Date.class) { BeanUtils.setProperty(bean, key, new Date(1)); } else if (fieldType == Long.class || fieldType == long.class) { BeanUtils.setProperty(bean, key, 17L); } else if (fieldType == Integer.class || fieldType == long.class) { BeanUtils.setProperty(bean, key, 11); } else if (fieldType == Set.class) { // Initialize to a linked hash set so that order is maintained. BeanUtils.setProperty(bean, key, new LinkedHashSet()); Type genericType = declaredField.getGenericType(); String typeName = genericType.getTypeName(); String typeClassName = typeName.substring(14, typeName.length() - 1); Class<?> typeClass = Class.forName(typeClassName); Set collection = (Set) BeanUtilsBean.getInstance().getPropertyUtils().getProperty(bean, key); populateSet(collection, typeClass); } else if (fieldType == Map.class) { Map<String, String> map = new LinkedHashMap<String, String>(); map.put("KEY-1", "VALUE-1"); map.put("KEY-2", "VALUE-2"); BeanUtils.setProperty(bean, key, map); } else if (fieldType.isEnum()) { BeanUtils.setProperty(bean, key, fieldType.getEnumConstants()[0]); } else if (fieldType.getPackage() != null && fieldType.getPackage().getName().startsWith("io.apiman.manager.api.beans")) { Object childBean = createBean(fieldType); BeanUtils.setProperty(bean, key, childBean); } else { throw new IllegalAccessException( "Failed to handle property named [" + key + "] type: " + fieldType.getSimpleName()); } // String capKey = StringUtils.capitalize(key); // System.out.println(key);; } catch (NoSuchFieldException e) { // Skip it - there is not really a bean property with this name! } } return bean; }
From source file:com.mstiles92.plugins.stileslib.config.ConfigObject.java
@SuppressWarnings("rawtypes") protected Object loadObject(Field field, ConfigurationSection cs, String path, int depth) throws Exception { Class clazz = getClassAtDepth(field.getGenericType(), depth); if (ConfigObject.class.isAssignableFrom(clazz) && isConfigurationSection(cs.get(path))) { return getConfigObject(clazz, cs.getConfigurationSection(path)); } else if (Location.class.isAssignableFrom(clazz) && isJSON(cs.get(path))) { return getLocation((String) cs.get(path)); } else if (Vector.class.isAssignableFrom(clazz) && isJSON(cs.get(path))) { return getVector((String) cs.get(path)); } else if (Map.class.isAssignableFrom(clazz) && isConfigurationSection(cs.get(path))) { return getMap(field, cs.getConfigurationSection(path), path, depth); } else if (clazz.isEnum() && isString(cs.get(path))) { return getEnum(clazz, (String) cs.get(path)); } else if (List.class.isAssignableFrom(clazz) && isConfigurationSection(cs.get(path))) { Class subClazz = getClassAtDepth(field.getGenericType(), depth + 1); if (ConfigObject.class.isAssignableFrom(subClazz) || Location.class.isAssignableFrom(subClazz) || Vector.class.isAssignableFrom(subClazz) || Map.class.isAssignableFrom(subClazz) || List.class.isAssignableFrom(subClazz) || subClazz.isEnum()) { return getList(field, cs.getConfigurationSection(path), path, depth); } else {/*w ww . ja v a 2 s .com*/ return cs.get(path); } } else { return cs.get(path); } }
From source file:org.openmrs.web.taglib.FieldGenTag.java
@SuppressWarnings("unchecked") public int doStartTag() throws JspException { if (type == null) { type = ""; }//from w w w . j ava 2s . co m if (formFieldName == null) { formFieldName = ""; } if (formFieldName.length() > 0) { FieldGenHandler handler = getHandlerByClassName(type); if (handler != null) { handler.setFieldGenTag(this); handler.run(); } else { StringBuilder output = new StringBuilder( "Cannot handle type [" + type + "]. Please add a module to handle this type."); if (type.equals("char") || type.indexOf("java.lang.Character") >= 0) { String startVal = ""; if (val != null) { startVal = val.toString(); } if (startVal.length() > 1) { startVal = startVal.substring(0, 1); } String fieldLength = this.parameterMap != null ? (String) this.parameterMap.get("fieldLength") : null; fieldLength = (fieldLength == null) ? DEFAULT_INPUT_CHAR_LENGTH : fieldLength; output.setLength(0); output.append("<input type=\"text\" name=\"").append(formFieldName).append("\" id=\"") .append(formFieldName).append("\" value=\""); output.append(startVal).append("\" size=\"").append(fieldLength) .append("\" maxlength=\"1\" />"); } else if (type.equals("int") || type.indexOf("java.lang.Integer") >= 0 || type.equals("long") || type.indexOf("java.lang.Long") >= 0) { String startVal = ""; if (val != null) { startVal = val.toString(); } String fieldLength = this.parameterMap != null ? (String) this.parameterMap.get("fieldLength") : null; fieldLength = (fieldLength == null) ? DEFAULT_INPUT_INT_LENGTH : fieldLength; output.setLength(0); output.append("<input type=\"text\" name=\"").append(formFieldName).append("\" id=\"") .append(formFieldName).append("\" value=\""); output.append(startVal).append("\" size=\"").append(fieldLength).append("\" />"); } else if (type.equals("float") || type.indexOf("java.lang.Float") >= 0 || type.equals("double") || type.indexOf("java.lang.Double") >= 0 || type.indexOf("java.lang.Number") >= 0) { String startVal = ""; if (val != null) { startVal = val.toString(); } String fieldLength = this.parameterMap != null ? (String) this.parameterMap.get("fieldLength") : null; fieldLength = (fieldLength == null) ? DEFAULT_INPUT_FLOAT_LENGTH : fieldLength; output.setLength(0); output.append("<input type=\"text\" name=\"").append(formFieldName).append("\" id=\"") .append(formFieldName).append("\" value=\""); output.append(startVal).append("\" size=\"").append(fieldLength).append("\" />"); } else if (type.equals("boolean") || type.indexOf("java.lang.Boolean") >= 0) { String startVal = ""; if (val != null) { startVal = val.toString(); } startVal = (startVal == null) ? "" : startVal.toLowerCase(); if ("false".equals(startVal) || "0".equals(startVal)) { startVal = "false"; } if ("true".equals(startVal) || "1".equals(startVal)) { startVal = "true"; } if ("unknown".equals(startVal) || "?".equals(startVal)) { startVal = "unknown"; } String forceInputType = this.parameterMap != null ? (String) this.parameterMap.get("forceInputType") : null; String isNullable = this.parameterMap != null ? (String) this.parameterMap.get("isNullable") : null; String trueLabel = this.parameterMap != null ? (String) this.parameterMap.get("trueLabel") : null; String falseLabel = this.parameterMap != null ? (String) this.parameterMap.get("falseLabel") : null; String unknownLabel = this.parameterMap != null ? (String) this.parameterMap.get("unknownLabel") : null; if (forceInputType == null) { forceInputType = ""; } if ("checkbox".equals(forceInputType)) { output.setLength(0); output.append("<input type=\"checkbox\" name=\"").append(formFieldName).append("\" id=\"") .append(formFieldName); output.append("\" value=\"true\"").append(("true".equals(startVal) ? " checked" : "")) .append("/> "); } else { if (isNullable == null) { isNullable = ""; } if (trueLabel == null) { trueLabel = Context.getMessageSourceService().getMessage("general.yes"); } if (falseLabel == null) { falseLabel = Context.getMessageSourceService().getMessage("general.no"); } if (unknownLabel == null) { unknownLabel = Context.getMessageSourceService().getMessage("general.unknown"); } if ("false".equalsIgnoreCase(isNullable) || "f".equalsIgnoreCase(isNullable) || "0".equals(isNullable)) { output.setLength(0); output.append("<input type=\"radio\" name=\"").append(formFieldName).append("\" id=\"") .append(formFieldName); output.append("_f\" value=\"false\"") .append(("false".equals(startVal) ? " checked" : "")).append("/> "); output.append(falseLabel); output.append(" "); output.append("<input type=\"radio\" name=\"").append(formFieldName).append("\" id=\"") .append(formFieldName); output.append("_t\" value=\"true\"").append(("true".equals(startVal) ? " checked" : "")) .append("/> "); output.append(trueLabel); } else { output.setLength(0); output.append("<input type=\"radio\" name=\"").append(formFieldName).append("\" id=\"") .append(formFieldName); output.append("_f\" value=\"false\"") .append(("false".equals(startVal) ? " checked" : "")).append("/> "); output.append(falseLabel); output.append(" "); output.append("<input type=\"radio\" name=\"").append(formFieldName).append("\" id=\"") .append(formFieldName); output.append("_t\" value=\"true\"").append(("true".equals(startVal) ? " checked" : "")) .append("/> "); output.append(trueLabel); output.append(" "); output.append("<input type=\"radio\" name=\"").append(formFieldName).append("\" id=\"") .append(formFieldName); output.append("_u\" value=\"unknown\"") .append(("unknown".equals(startVal) ? " checked" : "")).append("/> "); output.append(unknownLabel); } } } else if (type.indexOf("$") >= 0) { // this could be an enum - if so, let's display it String className = type; Class cls = null; try { cls = Class.forName(className); } catch (Exception e) { cls = null; log.error("Could not instantiate class for this enum of class name [" + className + "] in FieldGenTag"); } if (cls != null && cls.isEnum()) { Object[] enumConstants = cls.getEnumConstants(); if (enumConstants != null && enumConstants.length > 0) { String startVal = ""; if (val != null) { startVal = val.toString(); } log.debug("val is " + val); log.debug("val.toString is " + startVal); if (startVal == null) { startVal = ""; } output.setLength(0); output.append("<select name=\"").append(formFieldName).append("\" id=\"") .append(formFieldName).append("\">"); StringBuilder options = new StringBuilder(); for (int i = 0; i < enumConstants.length; i++) { options.append("<option value=\"").append(enumConstants[i].toString()).append("\"") .append(startVal.equals(enumConstants[i].toString()) ? " selected" : "") .append(">").append(enumConstants[i].toString()).append("</option>"); } output.append(options.toString()); output.append("</select> "); } } } else if (type.equals("dropDownList")) { String startVal = ""; if (val != null) { startVal = StringEscapeUtils.escapeHtml(val.toString()); } String items = this.parameterMap != null ? (String) this.parameterMap.get("items") : null; output.setLength(0); output.append("<select name=\"").append(formFieldName).append("\" id=\"").append(formFieldName) .append("\">"); if (items != null && !items.isEmpty()) { StringBuilder options = new StringBuilder(); for (String item : items.split(",")) { String escapedItem = StringEscapeUtils.escapeHtml(item); escapedItem = StringEscapeUtils.escapeJavaScript(escapedItem); options.append("<option value=\"").append(escapedItem).append("\"") .append(startVal.equals(escapedItem) ? " selected" : "").append(">") .append(escapedItem).append("</option>"); } output.append(options.toString()); } output.append("</select> "); } // end checking different built-in types try { pageContext.getOut().write(output.toString()); } catch (IOException e) { log.error(e); } } } if (url == null) { url = "default.field"; } // all fieldGens are contained in the /WEB-INF/view/fieldGen/ folder and end with .field if (!url.endsWith("field")) { url += ".field"; } url = "/fieldGen/" + url; // add attrs to request so that the controller (and field jsp) can see/use them pageContext.getRequest().setAttribute("org.openmrs.fieldGen.type", type); pageContext.getRequest().setAttribute("org.openmrs.fieldGen.formFieldName", formFieldName); pageContext.getRequest().setAttribute("org.openmrs.fieldGen.parameters", OpenmrsUtil.parseParameterList(parameters)); Map<String, Object> hmParamMap = (Map<String, Object>) pageContext.getRequest() .getAttribute("org.openmrs.fieldGen.parameterMap"); if (hmParamMap == null) { hmParamMap = new HashMap<String, Object>(); } if (this.parameterMap != null) { hmParamMap.putAll(this.parameterMap); } pageContext.getRequest().setAttribute("org.openmrs.fieldGen.parameterMap", hmParamMap); pageContext.getRequest().setAttribute("org.openmrs.fieldGen.object", val); pageContext.getRequest().setAttribute("org.openmrs.fieldGen.request", pageContext.getRequest()); try { pageContext.include(this.url); } catch (ServletException e) { log.error("ServletException while trying to include a file in FieldGenTag", e); } catch (IOException e) { log.error("IOException while trying to include a file in FieldGenTag", e); } /* log.debug("FieldGenTag has reqest of " + pageContext.getRequest().toString()); pageContext.getRequest().setAttribute("javax.servlet.include.servlet_path.fieldGen", url); FieldGenController fgc = new FieldGenController(); try { fgc.handleRequest((HttpServletRequest)pageContext.getRequest(), (HttpServletResponse)pageContext.getResponse()); } catch (ServletException e) { log.error("ServletException while attempting to pass control to FieldGenController in FieldGenTag"); } catch (IOException e) { log.error("IOException while attempting to pass control to FieldGenController in FieldGenTag"); } */ resetValues(); return SKIP_BODY; }
From source file:org.broadinstitute.sting.commandline.ArgumentTypeDescriptor.java
@Override public boolean supports(Class type) { if (isBinding(type)) return false; if (type.isPrimitive()) return true; if (type.isEnum()) return true; if (primitiveToWrapperMap.containsValue(type)) return true; try {/*from www . ja va 2s . c o m*/ type.getConstructor(String.class); return true; } catch (Exception ex) { // An exception thrown above means that the String constructor either doesn't // exist or can't be accessed. In either case, this descriptor doesn't support this type. return false; } }
From source file:com.amazonaws.hal.client.ConversionUtil.java
private static Object convertFromString(Class<?> clazz, String value) { if (String.class.isAssignableFrom(clazz)) { return value; } else if (int.class.isAssignableFrom(clazz) || Integer.class.isAssignableFrom(clazz)) { return new Integer(value); } else if (long.class.isAssignableFrom(clazz) || Long.class.isAssignableFrom(clazz)) { return new Long(value); } else if (short.class.isAssignableFrom(clazz) || Short.class.isAssignableFrom(clazz)) { return new Short(value); } else if (double.class.isAssignableFrom(clazz) || Double.class.isAssignableFrom(clazz)) { return new Double(value); } else if (float.class.isAssignableFrom(clazz) || Float.class.isAssignableFrom(clazz)) { return new Float(value); } else if (boolean.class.isAssignableFrom(clazz) || Boolean.class.isAssignableFrom(clazz)) { return Boolean.valueOf(value); } else if (char.class.isAssignableFrom(clazz) || Character.class.isAssignableFrom(clazz)) { return value.charAt(0); } else if (byte.class.isAssignableFrom(clazz) || Byte.class.isAssignableFrom(clazz)) { return new Byte(value); } else if (BigDecimal.class.isAssignableFrom(clazz)) { return new BigDecimal(value); } else if (BigInteger.class.isAssignableFrom(clazz)) { return new BigInteger(value); } else if (Date.class.isAssignableFrom(clazz)) { try {//from w ww .jav a2s . c o m return new Date(Long.parseLong(value)); } catch (NumberFormatException e) { try { return DatatypeConverter.parseDateTime(value).getTime(); } catch (IllegalArgumentException e1) { throw new RuntimeException("Unexpected date format: " + value + ". We currently parse xsd:datetime and milliseconds."); } } } else if (clazz.isEnum()) { try { //noinspection unchecked return Enum.valueOf((Class<Enum>) clazz, value); } catch (IllegalArgumentException e) { log.error(String.format( "'%s' is not a recognized enum value for %s. Returning default of %s instead.", value, clazz.getName(), clazz.getEnumConstants()[0])); return clazz.getEnumConstants()[0]; } } else { throw new RuntimeException("Not sure how to convert " + value + " to a " + clazz.getSimpleName()); } }
From source file:com.gdevelop.gwt.syncrpc.SyncClientSerializationStreamReader.java
private Object deserializeImpl(Class<?> customSerializer, Class<?> instanceClass, Object instance) throws NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, SerializationException, ClassNotFoundException { if (customSerializer != null) { deserializeWithCustomFieldDeserializer(customSerializer, instanceClass, instance); } else if (instanceClass.isArray()) { instance = deserializeArray(instanceClass, instance); } else if (instanceClass.isEnum()) { // Enums are deserialized when they are instantiated } else {/* w w w. java 2 s . c om*/ deserializeClass(instanceClass, instance); } return instance; }