5
5
import com .google .gson .reflect .TypeToken ;
6
6
import com .thoughtworks .go .plugin .api .request .GoPluginApiRequest ;
7
7
8
+ import java .util .Map ;
9
+
8
10
import static java .lang .String .format ;
9
11
10
12
class ParsedRequest {
@@ -15,7 +17,6 @@ class ParsedRequest {
15
17
private static final String PARAM_NOT_A_STRING_MESSAGE = "Expected `%s` param in request type `%s` to be a string" ;
16
18
private static final String PARAM_FAILED_TO_PARSE_TO_TYPE = "Failed to parse parameter `%s` for request type `%s`: %s" ;
17
19
private static final String PARAM_CONFIGURATIONS = "configurations" ;
18
- private static final String INVALID_REPO_CONFIGURATION_KEY = "Config repo configuration has invalid key `%s`" ;
19
20
private final String requestName ;
20
21
private final JsonObject params ;
21
22
@@ -70,15 +71,15 @@ String getStringParam(String paramName) {
70
71
}
71
72
}
72
73
73
- <T > T getParam (String paramName ) {
74
+ <V > Map < String , V > getParam (String paramName , Class < V > valueClass ) {
74
75
try {
75
76
JsonElement json = params .get (paramName );
76
77
77
78
if (null == json || json .isJsonNull ()) {
78
79
throw new RequestParseException (format (MISSING_PARAM_MESSAGE , paramName , requestName ));
79
80
}
80
81
81
- return GSON .fromJson (json , new TypeToken < T >() {} .getType ());
82
+ return GSON .fromJson (json , TypeToken . getParameterized ( Map . class , String . class , valueClass ) .getType ());
82
83
} catch (Exception e ) {
83
84
throw new RequestParseException (format (PARAM_FAILED_TO_PARSE_TO_TYPE , paramName , requestName , e .getMessage ()));
84
85
}
0 commit comments