Skip to content

Instantly share code, notes, and snippets.

@AFutureD
Created October 9, 2023 05:48
Show Gist options
  • Save AFutureD/2b22cc8e2fe4a31a1af62f76e5707963 to your computer and use it in GitHub Desktop.
Save AFutureD/2b22cc8e2fe4a31a1af62f76e5707963 to your computer and use it in GitHub Desktop.
@RequiredArgsConstructor
public class Client {
public <T> Result<T> execute(Object requset, Class<?>... types) {
String content = <json response>
return JSONObject.parseObject(content, buildType(ArrayUtil.append(new Class[]{Result.class}, types)));
}
private static Type buildType(Type... types) {
ParameterizedTypeImpl beforeType = null;
if (types != null && types.length > 0) {
for (int i = types.length - 1; i > 0; i--) {
beforeType = new ParameterizedTypeImpl(new Type[]{beforeType == null ? types[i] : beforeType}, null, types[i - 1]);
}
}
return beforeType;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment