Skip to content

Commit

Permalink
Fixed invalid JSON output in station_sample (comma)
Browse files Browse the repository at this point in the history
  • Loading branch information
DougLau committed Jun 25, 2024
1 parent 5fc2a4d commit 91c03cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/us/mn/state/dot/tms/server/StationImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,14 @@ public void writeSampleXml(Writer w, long stamp, int per_ms)
}

/** Write the current sample as a JSON object */
public boolean writeSampleJson(long stamp, int per_ms, Writer writer)
throws IOException
public boolean writeSampleJson(long stamp, int per_ms, Writer writer,
boolean first) throws IOException
{
int f = getFlow(stamp, per_ms);
int s = Math.round(getSpeed(stamp, per_ms));
if (f > MISSING_DATA || s > 0) {
if (first)
writer.write(',');
writeSampleJson(f, s, writer);
return true;
} else
Expand Down
8 changes: 5 additions & 3 deletions src/us/mn/state/dot/tms/server/StationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,15 @@ private void writeSampleJson(BufferedWriter writer) throws IOException {
writer.write("\"period\":30,\n");
writer.write("\"samples\":{\n");
Iterator<Station> it = StationHelper.iterator();
boolean first = true;
while (it.hasNext()) {
Station s = it.next();
if (s instanceof StationImpl) {
StationImpl si = (StationImpl) s;
if (si.writeSampleJson(stamp, per_ms, writer)) {
if (it.hasNext())
writer.write(',');
if (si.writeSampleJson(stamp, per_ms, writer,
first))
{
first = false;
writer.write('\n');
}
}
Expand Down

0 comments on commit 91c03cd

Please sign in to comment.