Created
October 9, 2023 05:48
-
-
Save AFutureD/2b22cc8e2fe4a31a1af62f76e5707963 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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