Skip to content

Commit

Permalink
Issue #10: fixed JSON error when returning an empty result set.
Browse files Browse the repository at this point in the history
  • Loading branch information
p-goetz authored and bsjaekel committed Jan 18, 2013
1 parent 6843fb2 commit c726c8b
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/tsd/GraphHandler.java
Expand Up @@ -366,16 +366,22 @@ private void execute() throws IOException {
final int nplotted = runGnuplot(query, basepath, plot);
if (query.hasQueryStringParam("json")) {
final StringBuilder buf = new StringBuilder(64);
buf.append("{\"plotted\":").append(nplotted).append(",\"etags\":[");
for (final Set<String> tags : plot.getAggregatedTags()) {
if (tags == null || tags.isEmpty()) {
buf.append("[]");
} else {
HttpQuery.toJsonArray(tags, buf);
final List<Set<String>> aggregatedTags = plot.getAggregatedTags();
buf.append("{\"plotted\":").append(nplotted);
if(aggregatedTags == null || aggregatedTags.isEmpty()) {
buf.append("[[]]");
} else {
buf.append(",\"etags\":[");
for (final Set<String> tags : plot.getAggregatedTags()) {
if (tags == null || tags.isEmpty()) {
buf.append("[]");
} else {
HttpQuery.toJsonArray(tags, buf);
}
buf.append(',');
}
buf.append(',');
buf.setCharAt(buf.length() - 1, ']');
}
buf.setCharAt(buf.length() - 1, ']');
// The "timing" field must remain last, loadCachedJson relies this.
buf.append(",\"timing\":").append(query.processingTimeMillis())
.append('}');
Expand Down

0 comments on commit c726c8b

Please sign in to comment.