Skip to content

Commit

Permalink
FORGE-2504: JsonResource prints a formatted output
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Oct 20, 2015
1 parent 76ac529 commit d4ef028
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import javax.json.JsonReader;
import javax.json.JsonStructure;
import javax.json.JsonWriter;
import javax.json.JsonWriterFactory;
import javax.json.stream.JsonGenerator;

import org.jboss.forge.addon.resource.AbstractFileResource;
import org.jboss.forge.addon.resource.Resource;
Expand Down Expand Up @@ -115,9 +117,10 @@ public JsonResource setContents(JsonStructure structure)
throw new IOException("Failed to create file: " + getUnderlyingResourceObject());
}
}

JsonWriterFactory writerFactory = Json
.createWriterFactory(Collections.singletonMap(JsonGenerator.PRETTY_PRINTING, true));
try (OutputStream out = getFileOperations().createOutputStream(getUnderlyingResourceObject());
JsonWriter writer = Json.createWriter(out))
JsonWriter writer = writerFactory.createWriter(out))
{
writer.write(structure);
}
Expand Down

0 comments on commit d4ef028

Please sign in to comment.