Skip to content

Commit

Permalink
FORGE-2500: Bug in JsonResourceImpl.setContents(String)
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Oct 19, 2015
1 parent e7b7b4d commit 99b2028
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public JsonResource setContents(InputStream data)
{
try (JsonReader reader = Json.createReader(data))
{
setContents(reader.readObject());
setContents(reader.read());
}
}
catch (Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ public static AddonArchive getDeployment()
.addAsAddonDependencies(
AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi"),
AddonDependencyEntry.create("org.jboss.forge.addon:parser-json"),
AddonDependencyEntry.create("org.jboss.forge.addon:resources")
);
AddonDependencyEntry.create("org.jboss.forge.addon:resources"));
return archive;
}

Expand Down Expand Up @@ -160,4 +159,17 @@ public void testJsonResourceDataWriteJsonObject() throws Exception
Assert.assertEquals("George", jsonObject.getString("firstName"));
Assert.assertEquals("Gastaldi", jsonObject.getString("lastName"));
}

// FORGE-2500
@Test
public void testJsonResourceDataWriteEmptyArrayString() throws Exception
{
File tmpFile = File.createTempFile("parser_json_test", ".json");
tmpFile.deleteOnExit();
Resource<File> resource = resourceFactory.create(tmpFile);
Assert.assertThat(resource, CoreMatchers.instanceOf(JsonResource.class));
JsonResource jsonResource = resource.reify(JsonResource.class);
jsonResource.setContents("[]"); // Json.createArrayBuilder().build().toString()
Assert.assertTrue(jsonResource.getJsonArray().isEmpty());
}
}

0 comments on commit 99b2028

Please sign in to comment.