From b09ecce9c72365e52aefa46f7e61b96258a79502 Mon Sep 17 00:00:00 2001 From: John Bogovic Date: Wed, 29 May 2024 11:19:36 -0400 Subject: [PATCH] fix: more permissive parsing of fill_value --- .../saalfeldlab/n5/zarr/ZArrayAttributes.java | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/janelia/saalfeldlab/n5/zarr/ZArrayAttributes.java b/src/main/java/org/janelia/saalfeldlab/n5/zarr/ZArrayAttributes.java index 4887cc5..10b4253 100644 --- a/src/main/java/org/janelia/saalfeldlab/n5/zarr/ZArrayAttributes.java +++ b/src/main/java/org/janelia/saalfeldlab/n5/zarr/ZArrayAttributes.java @@ -144,19 +144,12 @@ private static JsonElement parseFillValue(String fillValue, DataType dtype) { if (fillValue == null || fillValue.isEmpty()) return JsonNull.INSTANCE; - switch (dtype) { - case INT8: - case UINT8: - case INT16: - case UINT16: - case INT32: - case UINT32: - case INT64: - case UINT64: + // Long is more than Double, so try that first + try { return new JsonPrimitive(Long.parseLong(fillValue)); - default: - return new JsonPrimitive(Double.parseDouble(fillValue)); - } + } catch (final NumberFormatException ignore) {} + + return new JsonPrimitive(Double.parseDouble(fillValue)); } public long[] getShape() {