public static <T> T data(String data, Class<T> targetType) { return data(data.getBytes(), targetType); }
static DataFormat[] detectDataFormat(byte[] data) { if (data.length == 0) { return YAML_FIRST; } byte start = findFirstNonWhitespaceByte(data); if (start == '<') { return XML_FIRST; } else if (start == ' ' || (start == '-' && dataStartsWithYAMLMark(data))) { return YAML_FIRST; } else { return JSON_FIRST; } }
@SuppressWarnings("unchecked") public static <T> T data(byte[] data, Class<T> targetType) { if (data == null) { return null; } // don't parse if the target type is byte[] if (targetType == byte[].class) { return (T) data; } DataFormat[] formatsOrder = detectDataFormat(data); return tryToParseData(data, formatsOrder, targetType); }
@SuppressWarnings("unchecked") public static <T> T data(byte[] data, Class<T> targetType) { if (data == null) { return null; } // don't parse if the target type is byte[] if (targetType == byte[].class) { return (T) data; } DataFormat[] formatsOrder = detectDataFormat(data); return tryToParseData(data, formatsOrder, targetType); }
static DataFormat[] detectDataFormat(byte[] data) { if (data.length == 0) { return YAML_FIRST; } byte start = findFirstNonWhitespaceByte(data); if (start == '<') { return XML_FIRST; } else if (start == ' ' || (start == '-' && dataStartsWithYAMLMark(data))) { return YAML_FIRST; } else { return JSON_FIRST; } }
@Override public T map(HttpResp resp) { return !resultType.equals(void.class) ? Parse.data(resp.bodyBytes(), resultType) : null; }
public static <T> T data(String data, Class<T> targetType) { return data(data.getBytes(), targetType); }