List of usage examples for java.lang.reflect Type toString
public String toString()
From source file:de.itomig.itopenterprise.GetItopJSON.java
/** * convert a json string to an ArrayList of a CMDBObject Type * * @param json string/*from w w w.j a va 2 s . c o m*/ * @param T Type of data * @param context application context, call with =null when calling from background task * @param <T> Type of data * @return ArrayList<T> with the results, returns empty list when error or no data. */ public static <T> ArrayList<T> getArrayFromJson(String json, Type T, Context context) { ArrayList<T> list = new ArrayList<T>(); // check for server Error if ((json.length() >= 12) && json.substring(0, 12).contains("SERVER_ERROR")) { if (context != null) { Toast.makeText(context, json, Toast.LENGTH_LONG).show(); } else { Log.e(TAG, json); } return list; } String code = "100"; // json error code, "0" => everything is o.k. Log.d(TAG, "getArrayFromJson - Type=" + T.toString()); JSONObject jsonObject = null; try { jsonObject = new JSONObject(json); code = jsonObject.getString("code"); Log.d(TAG, "code=" + code); Log.d(TAG, "message=" + jsonObject.getString("message")); } catch (JSONException e) { Log.e(TAG, "error in getArrayFromJSON " + e.getMessage()); Toast.makeText(context, "error in getArrayFromJSON " + e.getMessage(), Toast.LENGTH_LONG).show(); } if ((jsonObject != null) && (code.trim().equals("0"))) { try { JSONObject objects = jsonObject.getJSONObject("objects"); Iterator<?> keys = objects.keys(); while (keys.hasNext()) { String key = (String) keys.next(); Log.d(TAG, "key=" + key); if (objects.get(key) instanceof JSONObject) { // Log.d(TAG,"obj="+objects.get(key).toString()); JSONObject o = (JSONObject) objects.get(key); int id = o.getInt("key"); Log.d(TAG, "id=" + id); JSONObject fields = o.getJSONObject("fields"); //Log.d(TAG, "fields=" + fields.toString()); final GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(ItopTicket.class, new ItopTicketDeserializer()); final Gson gson = gsonBuilder.create(); final T jf = gson.fromJson(fields.toString(), T); if (jf instanceof CMDBObject) { ((CMDBObject) jf).id = id; } list.add(jf); } } Log.d(TAG, "code=" + jsonObject.getString("code")); Log.d(TAG, "message=" + jsonObject.getString("message")); } catch (JSONException e) { Log.e(TAG, "objects = null in JSON response."); } } // endif (jsonObject != null) return list; }
From source file:com.phoenixnap.oss.ramlapisync.naming.SchemaHelper.java
private static JsonSchema extractSchemaInternal(Type clazz, Type genericType, String responseDescription, JavaDocStore javaDocStore, ObjectMapper m) throws JsonMappingException { SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); if (genericType != null) { try {/*from w w w . j a va2s. com*/ m.acceptJsonFormatVisitor(m.constructType(genericType), visitor); } catch (Exception ex) { logger.error("Unable to add JSON visitor for " + genericType.toString()); } } try { m.acceptJsonFormatVisitor(m.constructType(clazz), visitor); } catch (Exception ex) { logger.error("Unable to add JSON visitor for " + clazz.toString()); } JsonSchema jsonSchema = visitor.finalSchema(); if (jsonSchema instanceof ObjectSchema && javaDocStore != null) { ObjectSchema objectSchema = (ObjectSchema) jsonSchema; if (objectSchema.getProperties() != null) { for (Entry<String, JsonSchema> cSchema : objectSchema.getProperties().entrySet()) { JavaDocEntry javaDocEntry = javaDocStore.getJavaDoc(cSchema.getKey()); if (javaDocEntry != null && StringUtils.hasText(javaDocEntry.getComment())) { cSchema.getValue().setDescription(javaDocEntry.getComment()); } } } } else if (jsonSchema instanceof ValueTypeSchema && StringUtils.hasText(responseDescription)) { ValueTypeSchema valueTypeSchema = (ValueTypeSchema) jsonSchema; valueTypeSchema.setDescription(responseDescription); } else if (jsonSchema instanceof ArraySchema && genericType != null) { ArraySchema arraySchema = (ArraySchema) jsonSchema; arraySchema.setItemsSchema(extractSchemaInternal(genericType, TypeHelper.inferGenericType(genericType), responseDescription, javaDocStore, m)); } return jsonSchema; }
From source file:com.sm.query.utils.QueryUtils.java
public static boolean isSameType(Type left, Type right) { if (left == right) return true; else if (left.toString().contains(right.toString()) || right.toString().contains(left.toString())) return true; else//from w ww .jav a 2 s.c o m return false; }
From source file:com.bstek.dorado.data.method.MethodAutoMatchingUtils.java
private static String getClassName(Type type) { return (type instanceof Class) ? ((Class<?>) type).getName() : type.toString(); }
From source file:sample.action.sqlholder.SQLHolderAction.java
public ActionForward doView() throws Exception { log.debug("SQLHolder"); HashMap m = new HashMap(); m.put("damdam", "lslslsl"); System.out.println(SqlHolder.getSql("main", m)); Type type = getClass().getDeclaredMethods()[0].getGenericReturnType(); log.debug(type.toString()); return ActionHelper.findForward("view"); }
From source file:fm.audiobox.core.models.Playlists.java
public Playlist getPlaylistByType(Type type) { return this.getPlaylistByType(type.toString()); }
From source file:fm.audiobox.core.models.Playlists.java
public List<Playlist> getPlaylistsByType(Type type) { return this.getPlaylistsByType(type.toString()); }
From source file:com.hrules.darealmvp.DRDialogFragmentV4.java
@SuppressWarnings("unchecked") private P internalGetPresenter() throws java.lang.InstantiationException, IllegalAccessException, ClassNotFoundException { Class clazz = getClass();// ww w . j a v a 2s. com Type genericSuperclass; for (;;) { genericSuperclass = clazz.getGenericSuperclass(); if (genericSuperclass instanceof ParameterizedType) { break; } clazz = clazz.getSuperclass(); } Type presenterClass = ((ParameterizedType) genericSuperclass).getActualTypeArguments()[0]; return (P) Class.forName(presenterClass.toString().split(" ")[1]).newInstance(); }
From source file:org.ocelotds.core.services.ArgumentConvertor.java
private JavaType getJavaType(Type type) { Class clazz;/*from w ww. j av a 2s .c o m*/ logger.debug("Computing type of {} - {}", type.getClass(), type.toString()); if (type instanceof ParameterizedType) { clazz = (Class) ((ParameterizedType) type).getRawType(); } else { clazz = (Class) type; } JavaType javaType; Type actualType; if (Collection.class.isAssignableFrom(clazz)) { ParameterizedType pt = (ParameterizedType) type; actualType = pt.getActualTypeArguments()[0]; JavaType t1 = getJavaType(actualType); javaType = CollectionType.construct(Collection.class, t1); } else if (clazz.isArray()) { Class t = clazz.getComponentType(); JavaType t1 = getJavaType(t); javaType = ArrayType.construct(t1, null, null); } else if (Map.class.isAssignableFrom(clazz)) { ParameterizedType pt = (ParameterizedType) type; actualType = pt.getActualTypeArguments()[0]; JavaType t1 = getJavaType(actualType); actualType = pt.getActualTypeArguments()[1]; JavaType t2 = getJavaType(actualType); javaType = MapType.construct(Map.class, t1, t2); } else { javaType = SimpleType.construct(clazz); } return javaType; }
From source file:ca.appvelopers.mcgillmobile.model.retrofit.ScheduleConverter.java
@Override public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {/*from www. j av a2s . co m*/ if (!type.toString().equals(this.type.toString())) { //This can only convert a list of courses return null; } return new ScheduleConverter(); }