protected static final String WRITE_PERMISSION_NAME = "write";
protected static final String READ_PERMISSION_NAME = "read";
protected static final String FAILED_TO_REQUEST_BEGIN_MSG = "Failed to request ";
- private static final Type REPOSITORY_TEAM_LIST_TYPE = TypeToken.getParameterized(List.class, GsonRepositoryTeam.class).getType();
- private static final Type REPOSITORY_COLLABORATORS_LIST_TYPE = TypeToken.getParameterized(List.class, GsonRepositoryCollaborator.class).getType();
- private static final Type ORGANIZATION_LIST_TYPE = TypeToken.getParameterized(List.class, GithubBinding.GsonInstallation.class).getType();
+ private static final TypeToken<List<GsonRepositoryTeam>> REPOSITORY_TEAM_LIST_TYPE = new TypeToken<>() {
+ };
+ private static final TypeToken<List<GsonRepositoryCollaborator>> REPOSITORY_COLLABORATORS_LIST_TYPE = new TypeToken<>() {
+ };
+ private static final TypeToken<List<GithubBinding.GsonInstallation>> ORGANIZATION_LIST_TYPE = new TypeToken<>() {
+ };
protected final GithubApplicationHttpClient githubApplicationHttpClient;
protected final GithubAppSecurity appSecurity;
private final GitHubSettings gitHubSettings;
public class GitlabApplicationClient {
private static final Logger LOG = LoggerFactory.getLogger(GitlabApplicationClient.class);
private static final Gson GSON = new Gson();
- private static final Type GITLAB_GROUP = TypeToken.getParameterized(List.class, GsonGroup.class).getType();
- private static final Type GITLAB_USER = TypeToken.getParameterized(List.class, GsonUser.class).getType();
+ private static final TypeToken<List<GsonGroup>> GITLAB_GROUP = new TypeToken<>() {
+ };
+ private static final TypeToken<List<GsonUser>> GITLAB_USER = new TypeToken<>() {
+ };
protected static final String PRIVATE_TOKEN = "Private-Token";
private static final String GITLAB_GROUPS_MEMBERS_ENDPOINT = "/groups/%s/members";
public static List<Project> parseJsonArray(String json) {
Gson gson = new Gson();
return gson.fromJson(json, new TypeToken<LinkedList<Project>>() {
- }.getType());
+ });
}
public long getId() {
private static final String ENDPOINT = "/test-endpoint";
- private static final Type STRING_LIST_TYPE = TypeToken.getParameterized(List.class, String.class).getType();
+ private static final TypeToken<List<String>> STRING_LIST_TYPE = new TypeToken<>() {
+ };
private Gson gson = new Gson();
}
public static List<GsonEmail> parse(String json) {
- Type collectionType = new TypeToken<Collection<GsonEmail>>() {
- }.getType();
Gson gson = new Gson();
- return gson.fromJson(json, collectionType);
+ return gson.fromJson(json, new TypeToken<List<GsonEmail>>() {
+ });
}
}
}
public static List<GsonTeam> parse(String json) {
- Type collectionType = new TypeToken<Collection<GsonTeam>>() {
- }.getType();
Gson gson = new Gson();
- return gson.fromJson(json, collectionType);
+ return gson.fromJson(json, new TypeToken<List<GsonTeam>>() {
+ });
}
public static class GsonOrganization {
}
static List<GsonGroup> parse(String json) {
- Type collectionType = new TypeToken<Collection<GsonGroup>>() {}.getType();
Gson gson = new Gson();
- return gson.fromJson(json, collectionType);
+ return gson.fromJson(json, new TypeToken<List<GsonGroup>>() {
+ });
}
}
}
public static QPMeasureData fromJson(String json) {
- return new QPMeasureData(StreamSupport.stream(new JsonParser().parse(json).getAsJsonArray().spliterator(), false)
+ return new QPMeasureData(StreamSupport.stream(JsonParser.parseString(json).getAsJsonArray().spliterator(), false)
.map(jsonElement -> {
JsonObject jsonProfile = jsonElement.getAsJsonObject();
return new QualityProfile(
package org.sonar.server.authentication;
import com.google.common.base.Strings;
-import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
+import com.google.gson.reflect.TypeToken;
import java.io.UnsupportedEncodingException;
-import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
*/
private static final String RETURN_TO_PARAMETER = "return_to";
- private static final Type JSON_MAP_TYPE = new TypeToken<HashMap<String, String>>() {
- }.getType();
+ private static final TypeToken<Map<String, String>> JSON_MAP_TYPE = new TypeToken<>() {
+ };
@Override
public void init(HttpRequest request, HttpResponse response) {
db.components().insertSnapshot(projectData.getMainBranchComponent());
Date now = new Date();
- JsonParser jsonParser = new JsonParser();
- JsonElement jsonTree = jsonParser.parseString(IOUtils.toString(getClass().getResource("tree-example.json"), UTF_8));
+ JsonElement jsonTree = JsonParser.parseString(IOUtils.toString(getClass().getResource("tree-example.json"), UTF_8));
JsonArray components = jsonTree.getAsJsonObject().getAsJsonArray("components");
for (int i = 0; i < components.size(); i++) {
JsonElement componentAsJsonElement = components.get(i);
.setParam("asc", "false")
.execute();
- JsonElement parse = new JsonParser().parse(response.getInput());
+ JsonElement parse = JsonParser.parseString(response.getInput());
assertThat(parse.getAsJsonObject().get("issues").getAsJsonArray())
.extracting(o -> o.getAsJsonObject().get("key").getAsString())
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
-import java.lang.reflect.Type;
import java.util.Collections;
import java.util.List;
import java.util.Map;
private static final Collector<CharSequence, ?, String> COMMA_JOINER = Collectors.joining(",");
private static final String MSG_NO_EMPTY_VALUE = "A non empty value must be provided";
private static final int VALUE_MAXIMUM_LENGTH = 4000;
+ private static final TypeToken<Map<String, String>> MAP_TYPE_TOKEN = new TypeToken<>() {
+ };
private final PropertyDefinitions propertyDefinitions;
private final DbClient dbClient;
}
private static Map<String, String> readOneFieldValues(String json, String key) {
- Type type = new TypeToken<Map<String, String>>() {
- }.getType();
Gson gson = GsonHelper.create();
try {
- return gson.fromJson(json, type);
+ return gson.fromJson(json, MAP_TYPE_TOKEN);
} catch (JsonSyntaxException e) {
throw BadRequestException.create(format("JSON '%s' does not respect expected format for setting '%s'. Ex: {\"field1\":\"value1\", \"field2\":\"value2\"}", json, key));
}
@CheckForNull
private static String tryParseAsJsonError(String responseContent) {
try {
- JsonParser parser = new JsonParser();
- JsonObject obj = parser.parse(responseContent).getAsJsonObject();
+ JsonObject obj = JsonParser.parseString(responseContent).getAsJsonObject();
JsonArray errors = obj.getAsJsonArray("errors");
List<String> errorMessages = new ArrayList<>();
for (JsonElement e : errors) {
}
private static String pretty(String json) {
- JsonElement gson = new JsonParser().parse(json);
+ JsonElement gson = JsonParser.parseString(json);
return new GsonBuilder().setPrettyPrinting().serializeNulls().create().toJson(gson);
}
}