/** * Parse the json string and converts the raw value to the target type * @since 0.5.0b */ public static <T> List<T> decodeList(String json, Class<? extends T> valueType){ T[] obj = decodeArray(json,valueType); return New.arrayList(obj); }
/** * Parse the response content as json and decodes to array. */ default <T> T[] decodeJsonArray(Class<T> componentType) { return JSON.decodeArray(getContent(), componentType); }
Type[] actualTypes = pType.getActualTypeArguments(); if (rawType.isAssignableFrom(List.class)) { Object[] arr = JSON.decodeArray(jsonStr, (Class<?>) actualTypes[0]); T val = (T) Arrays.stream(arr).collect(Collectors.toList()); return val;
protected GenericDbDriver[] loadDrivers() { String configFile = this.getClass().getSimpleName() + ".driver.json"; Resource r = Resources.getResource(this.getClass(),configFile); if(!r.exists()){ return EMPTY_DRIVES; } try { String keyPrefix = I18N.getLocalizedKeyPrefix(this) + ".drivers"; try(Reader reader = r.getInputStreamReader()){ GenericDbDriver[] drivers = JSON.decodeArray(reader, GenericDbDriver.class); for(GenericDbDriver driver : drivers){ I18N.localize(messageSource, driver, keyPrefix + "." + driver.getName()); } return drivers; } } catch (IOException e) { throw new NestedIOException("Error reading driver config file '" + r.getDescription() + "', " + e.getMessage(), e); } } }