Compare commits
2 Commits
21643e5d63
...
92ee656a5d
Author | SHA1 | Date |
---|---|---|
gulerdav | 92ee656a5d | |
Elias Csomor | c64339c945 |
|
@ -21,13 +21,9 @@ 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;
|
||||||
URL imageUrl = PlantList.class.getResource(String.format("images/%s", parser.getText()));
|
InputStream is = PlantList.class.getResourceAsStream(String.format("images/%s", parser.getText()));
|
||||||
if (imageUrl != null) {
|
if (is != 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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue