List of usage examples for com.google.gson.internal Primitives isPrimitive
public static boolean isPrimitive(Type type)
From source file:co.cask.cdap.internal.app.runtime.procedure.DefaultProcedureRequest.java
License:Apache License
@SuppressWarnings("unchecked") @Override/* w w w . j a va 2 s. c om*/ public <T> T getArgument(String key, Class<T> type) { Preconditions.checkNotNull(type, "Type cannnot be null."); Preconditions.checkArgument(!Void.class.equals(type) && !Void.TYPE.equals(type), "Void type not supported."); String value = getArgument(key); if (String.class.equals(type)) { return (T) value; } Class<T> resolvedType = type; if (Primitives.isPrimitive(resolvedType)) { resolvedType = Primitives.wrap(type); } if (Primitives.isWrapperType(resolvedType)) { // All wrapper has the valueOf(String) method try { return (T) resolvedType.getMethod("valueOf", String.class).invoke(null, value); } catch (Exception e) { // Should not happen throw Throwables.propagate(e); } } if (URL.class.equals(type)) { try { return (T) new URL(value); } catch (MalformedURLException e) { throw Throwables.propagate(e); } } if (URI.class.equals(type)) { return (T) URI.create(value); } // TODO: Maybe support gson decode the type?? throw new ClassCastException("Fail to convert from String to " + type); }
From source file:com.jsmartframework.web.manager.BeanHelper.java
License:Open Source License
boolean hasPrimitiveAuthFields(Class<?> clazz) { Field[] fields = getAuthFields(clazz); for (int i = 0; i < fields.length; i++) { if (Primitives.isPrimitive(fields[i].getGenericType())) { return true; }//from www. j a v a 2s. co m } return false; }
From source file:com.jsmartframework.web.manager.ExpressionHandler.java
License:Open Source License
String handleSubmitExpression(String expr, String jParam) throws ServletException, IOException { Object response = null;/*from ww w. j a va 2 s. c om*/ Matcher matcher = EL_PATTERN.matcher(expr); if (matcher.find()) { String beanMethod = matcher.group(1); String[] methodSign = beanMethod.split(Constants.EL_SEPARATOR); HttpServletRequest request = WebContext.getRequest(); if (methodSign.length > 0 && WebContext.containsAttribute(methodSign[0])) { Object bean = getExpressionBean(methodSign[0]); String elBeanMethod = String.format(Constants.JSP_EL, beanMethod); // Check authorization to execute method if (!HANDLER.checkExecuteAuthorization(bean, elBeanMethod, request)) { return null; } // Call mapped method with @PreSubmit / @PreAction annotation for specific action boolean preActionValidated = HANDLER.executePreSubmit(bean, methodSign[methodSign.length - 1]); preActionValidated &= HANDLER.executePreAction(bean, methodSign[methodSign.length - 1]); if (preActionValidated) { Object[] arguments = null; String[] paramArgs = request.getParameterValues(TagHandler.J_SBMT_ARGS + jParam); AnnotatedFunction function = HANDLER.beanMethodFunctions.get(beanMethod); if (paramArgs != null) { arguments = new Object[paramArgs.length]; boolean unescape = HANDLER.containsUnescapeMethod(methodSign); for (int i = 0; i < paramArgs.length; i++) { if (function != null) { Class<?> argClass = function.getArgumentType(i); if (argClass != null && !Primitives.isPrimitive(argClass) && !argClass.equals(String.class)) { arguments[i] = GSON.fromJson(paramArgs[i], argClass); continue; } } arguments[i] = unescape ? paramArgs[i] : escapeValue(paramArgs[i]); } } // Call submit method ELContext context = WebContext.getPageContext().getELContext(); MethodExpression methodExpr = WebContext.getExpressionFactory().createMethodExpression(context, elBeanMethod, null, arguments != null ? new Class<?>[arguments.length] : new Class<?>[] {}); response = methodExpr.invoke(context, arguments); if (function != null && function.hasProduces()) { switch (function.getProduces()) { case JSON: WebContext.writeResponseAsJson(response); break; case XML: WebContext.writeResponseAsXmlQuietly(response); break; case STRING: WebContext.writeResponseAsString(response.toString()); break; } // Reset response to be passed to path analysis response = null; } // Call mapped method with @PostSubmit / @PostAction annotation for specific action HANDLER.executePostSubmit(bean, methodSign[methodSign.length - 1]); HANDLER.executePostAction(bean, methodSign[methodSign.length - 1]); } } } return response != null ? response.toString() : null; }
From source file:nl.colorize.util.xml.XMLConverter.java
License:Apache License
private boolean isSimpleType(Object obj) { if (obj == null) { return true; }// w w w. j a v a2 s. co m Class<?> type = obj.getClass(); return Primitives.isPrimitive(type) || Primitives.isWrapperType(type) || type == String.class; }
From source file:org.eclipse.che.plugin.typescript.dto.model.FieldAttributeModel.java
License:Open Source License
/** * Build a new field model based on the name and Java type * * @param fieldName//from w w w . j ava2 s .co m * the name of the field * @param type * the Java raw type that will allow further analyzes */ public FieldAttributeModel(String fieldName, Type type) { this.fieldName = fieldName; this.type = type; this.typeName = convertType(type); if (typeName.startsWith("Array<") || typeName.startsWith("Map<")) { this.needInitialize = true; } if (this.type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) this.type; Type rawType = parameterizedType.getRawType(); analyzeParametrizedType(parameterizedType, rawType); } else if (Primitives.isPrimitive(this.type) || Primitives.isWrapperType(this.type) || String.class.equals(this.type)) { this.isPrimitive = true; } else if (this.type instanceof Class && ((Class) this.type).isAnnotationPresent(DTO.class)) { this.isDto = true; dtoImpl = this.type.getTypeName() + "Impl"; } else if (this.type instanceof Class && ((Class) this.type).isEnum()) { this.isEnum = true; } }