Compare commits

..

No commits in common. "92ee656a5dc339e8384e55dc7a9cef80f5d36f02" and "21643e5d63715acfffb1a4e974b7e4d6acd89c86" have entirely different histories.

1 changed files with 7 additions and 3 deletions

View File

@ -21,9 +21,13 @@ public class PlantImageDeserializer extends JsonDeserializer<Image> {
@Override @Override
public Image deserialize(JsonParser parser, DeserializationContext context) throws IOException { public Image deserialize(JsonParser parser, DeserializationContext context) throws IOException {
Image result = null; Image result = null;
InputStream is = PlantList.class.getResourceAsStream(String.format("images/%s", parser.getText())); URL imageUrl = PlantList.class.getResource(String.format("images/%s", parser.getText()));
if (is != null) { if (imageUrl != null) {
try (InputStream is = new FileInputStream(new File(imageUrl.toURI()))) {
result = new Image(is); result = new Image(is);
} catch (IllegalArgumentException | URISyntaxException e) {
throw new IOException(String.format("Cannot find Image \"%s\"\n", imageUrl.getFile()));
}
} }
return result; return result;
} }