}
private void writeComponents(JsonWriter json, Collection<ComponentDto> components, Map<String, ComponentDto> projectsByComponentUuid) {
json.name("components").beginArray();
for (ComponentDto component : components) {
ComponentDto project = projectsByComponentUuid.get(component.uuid());
json.beginObject()
.prop("uuid", component.uuid())
.prop("key", component.key())
.prop("id", component.getId())
.prop("enabled", component.isEnabled())
.prop("qualifier", component.qualifier())
.prop("name", component.name())
.prop("longName", component.longName())
.prop("path", component.path())
// On a root project, subProjectId is null but projectId is equal to itself, which make no sense.
.prop("projectId", (component.projectUuid() != null && component.subProjectId() != null) ? project.getId() : null)
.prop("subProjectId", component.subProjectId())
.endObject();
}
json.endArray();
}