public static <T> T unmarshalFromByte(byte[] bytes, TypeReference<T> type) { return (T) JSON.parseObject(bytes, type.getType()); }
public <T> T readObject(TypeReference<T> typeRef) { return readObject(typeRef.getType()); }
public <T> T readObject(TypeReference<T> typeRef) { return readObject(typeRef.getType()); }
public <T> T getObject(String key, TypeReference typeReference) { Object obj = map.get(key); if (typeReference == null) { return (T) obj; } return TypeUtils.cast(obj, typeReference.getType(), ParserConfig.getGlobalInstance()); }
/** * @since 1.2.33 */ public <T> T toJavaObject(TypeReference typeReference) { Type type = typeReference != null ? typeReference.getType() : null; return TypeUtils.cast(this, type, ParserConfig.getGlobalInstance()); }
@SuppressWarnings("unchecked") public <T> T getAsObject(TypeReference<T> typeReference) { Class<T> clazz = (Class<T>) typeReference.getType(); for (MessageConverter messageConverter : messageConverters) { if (messageConverter.canConvert(clazz, response)) { try { return messageConverter.convert(clazz, response); } catch (IOException e) { throw new RuntimeException("IO error on convert to " + clazz, e); } } } if (clazz.isAssignableFrom(ApiResult.class)) { return (T) new ApiResult(); } throw new RuntimeException("cannot convert to " + clazz); }
public static <T> T unmarshalFromByte(byte[] bytes, TypeReference<T> type) { return (T) JSON.parseObject(bytes, type.getType()); }
public static <T> T unmarshalFromByte(byte[] bytes, TypeReference<T> type) { return (T) JSON.parseObject(bytes, type.getType()); }
/** * FastJson parse String to Object by TypeReference * * @param value * @param type * @return * * @see com.alibaba.fastjson.TypeReference * @see com.alibaba.fastjson.JSON#parseObject(String, TypeReference, com.alibaba.fastjson.parser.Feature...) */ @SuppressWarnings("unchecked") protected <T> T parseObject(final String value, final TypeReference<T> type) { if (StringUtils.isEmpty(value)) { return null; } if (type.getType() == String.class) { return (T) value; } return JSON.parseObject(value, type); }
@SuppressWarnings("unchecked") public static final <T> T parseObject(String text, TypeReference<T> type, Feature... features) { return (T) parseObject(text, type.getType(), ParserConfig.getGlobalInstance(), DEFAULT_PARSER_FEATURE, features); }
@SuppressWarnings("unchecked") @Override public <T> T get(final String key, final TypeReference<T> type) { final String value = get(key); if (StringUtils.isBlank(value)) { if (String.class.getName().equals(type.getType().getTypeName())) { return (T) value; } return null; } return parseObject(value, type); }
private static <T> List<T> configValueToItems(String configValue, Class<T> clazz, ParamBuffer pb) { try { TypeReference<ObjectValues<T>> reference = new TypeReference<ObjectValues<T>>(clazz) { }; ObjectValues<T> temp = JSON.parseObject(configValue, reference.getType()); return temp.getItems(); } catch (JSONException e) { log.error("Parse json error, {}, configValue={}", pb, configValue, e); throw new ServiceException(ResultCode.SERVER_INNER_ERROR, e); } }
public static <T> T load(String path, TypeReference<T> typeReference, Object hint, boolean ignoreResourceNotFound) { BeanSpec spec = BeanSpec.of(typeReference.getType(), injector); return __load(path, spec, hint, ignoreResourceNotFound); }
public static <T> T load(String path, TypeReference<T> typeReference, Object hint, boolean ignoreResourceNotFound) { BeanSpec spec = BeanSpec.of(typeReference.getType(), injector); return __load(path, spec, hint, ignoreResourceNotFound); }
public <T> T getAsObject(TypeReference<T> typeReference) { if (isJsonResult) { return JSON.parseObject(getAsString(), typeReference); } if (isXmlResult) { @SuppressWarnings("unchecked") Class<T> clazz = (Class<T>) typeReference.getType(); return XmlStream.fromXML(getAsString(), clazz); } return null; }
@SuppressWarnings("unchecked") public <T> T getAsObject(TypeReference<T> typeReference) { Class<T> clazz = (Class<T>) typeReference.getType(); for (MessageConverter messageConverter : messageConverters) { if (messageConverter.canConvert(clazz, response)) { try { return messageConverter.convert(clazz, response); } catch (IOException e) { throw new RuntimeException("IO error on convert to " + clazz, e); } } } if (clazz.isAssignableFrom(ApiResult.class)) { return (T) new ApiResult(); } throw new RuntimeException("cannot convert to " + clazz); }