long nbOfProjects = dbClient.componentDao().countGhostProjects(dbSession, organization.getUuid(), query);
List<ComponentDto> projects = dbClient.componentDao().selectGhostProjects(dbSession, organization.getUuid(), query,
searchOptions.getOffset(), searchOptions.getLimit());
- JsonWriter json = response.newJsonWriter().beginObject();
- writeProjects(json, projects, desiredFields);
- searchOptions.writeJson(json, nbOfProjects);
- json.endObject().close();
+ try (JsonWriter json = response.newJsonWriter()) {
+ json.beginObject();
+ writeProjects(json, projects, desiredFields);
+ searchOptions.writeJson(json, nbOfProjects);
+ json.endObject();
+ }
}
}
}
static void writeResponse(BulkChangeResult result, Response response) {
- JsonWriter json = response.newJsonWriter().beginObject();
- json.prop("succeeded", result.countSucceeded());
- json.prop("failed", result.countFailed());
- WebServiceEngine.writeErrors(json, result.getErrors());
- json.endObject().close();
+ try (JsonWriter json = response.newJsonWriter()) {
+ json.beginObject();
+ json.prop("succeeded", result.countSucceeded());
+ json.prop("failed", result.countFailed());
+ WebServiceEngine.writeErrors(json, result.getErrors());
+ json.endObject();
+ }
}
}
Paging paging = forPageIndex(page).withPageSize(pageSize).andTotal(total);
List<UserMembershipDto> users = dbClient.groupMembershipDao().selectMembers(dbSession, query, paging.offset(), paging.pageSize());
- JsonWriter json = response.newJsonWriter().beginObject();
- writeMembers(json, users);
- writePaging(json, paging);
- json.endObject().close();
+ try (JsonWriter json = response.newJsonWriter()) {
+ json.beginObject();
+ writeMembers(json, users);
+ writePaging(json, paging);
+ json.endObject();
+ }
}
}
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.text.JsonWriter;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
return;
}
- response
- .newJsonWriter()
- .beginObject()
- .prop("format", action.responseExampleFormat())
- .prop("example", action.responseExampleAsString())
- .endObject()
- .close();
+ try (JsonWriter json = response.newJsonWriter()) {
+ json.beginObject()
+ .prop("format", action.responseExampleFormat())
+ .prop("example", action.responseExampleAsString())
+ .endObject();
+ }
}
@Override