Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public final class JsonMapper {
private JsonMapper() {}

public static String toString(JsonValue value) {
if (value instanceof JsonValue.JsonNull) {
if (value == null || value instanceof JsonValue.JsonNull) {
return null;
}
if (value instanceof JsonValue.JsonString s) {
Expand All @@ -28,39 +28,39 @@ public static int toInt(JsonValue value) {
if (value instanceof JsonValue.JsonNumber n) {
return Integer.parseInt(n.value());
}
throw new JsonException("Expected JSON number but got " + value.getClass().getSimpleName());
throw new JsonException("Expected JSON number but got " + (value == null ? "null" : value.getClass().getSimpleName()));
}

public static long toLong(JsonValue value) {
if (value instanceof JsonValue.JsonNumber n) {
return Long.parseLong(n.value());
}
throw new JsonException("Expected JSON number but got " + value.getClass().getSimpleName());
throw new JsonException("Expected JSON number but got " + (value == null ? "null" : value.getClass().getSimpleName()));
}

public static double toDouble(JsonValue value) {
if (value instanceof JsonValue.JsonNumber n) {
return Double.parseDouble(n.value());
}
throw new JsonException("Expected JSON number but got " + value.getClass().getSimpleName());
throw new JsonException("Expected JSON number but got " + (value == null ? "null" : value.getClass().getSimpleName()));
}

public static float toFloat(JsonValue value) {
if (value instanceof JsonValue.JsonNumber n) {
return Float.parseFloat(n.value());
}
throw new JsonException("Expected JSON number but got " + value.getClass().getSimpleName());
throw new JsonException("Expected JSON number but got " + (value == null ? "null" : value.getClass().getSimpleName()));
}

public static boolean toBoolean(JsonValue value) {
if (value instanceof JsonValue.JsonBoolean b) {
return b.value();
}
throw new JsonException("Expected JSON boolean but got " + value.getClass().getSimpleName());
throw new JsonException("Expected JSON boolean but got " + (value == null ? "null" : value.getClass().getSimpleName()));
}

public static Integer toIntegerBoxed(JsonValue value) {
if (value instanceof JsonValue.JsonNull) {
if (value == null || value instanceof JsonValue.JsonNull) {
return null;
}
if (value instanceof JsonValue.JsonNumber n) {
Expand All @@ -70,7 +70,7 @@ public static Integer toIntegerBoxed(JsonValue value) {
}

public static Long toLongBoxed(JsonValue value) {
if (value instanceof JsonValue.JsonNull) {
if (value == null || value instanceof JsonValue.JsonNull) {
return null;
}
if (value instanceof JsonValue.JsonNumber n) {
Expand All @@ -80,7 +80,7 @@ public static Long toLongBoxed(JsonValue value) {
}

public static Double toDoubleBoxed(JsonValue value) {
if (value instanceof JsonValue.JsonNull) {
if (value == null || value instanceof JsonValue.JsonNull) {
return null;
}
if (value instanceof JsonValue.JsonNumber n) {
Expand All @@ -90,7 +90,7 @@ public static Double toDoubleBoxed(JsonValue value) {
}

public static Float toFloatBoxed(JsonValue value) {
if (value instanceof JsonValue.JsonNull) {
if (value == null || value instanceof JsonValue.JsonNull) {
return null;
}
if (value instanceof JsonValue.JsonNumber n) {
Expand All @@ -100,7 +100,7 @@ public static Float toFloatBoxed(JsonValue value) {
}

public static Boolean toBooleanBoxed(JsonValue value) {
if (value instanceof JsonValue.JsonNull) {
if (value == null || value instanceof JsonValue.JsonNull) {
return null;
}
if (value instanceof JsonValue.JsonBoolean b) {
Expand All @@ -110,7 +110,7 @@ public static Boolean toBooleanBoxed(JsonValue value) {
}

public static BigDecimal toBigDecimal(JsonValue value) {
if (value instanceof JsonValue.JsonNull) {
if (value == null || value instanceof JsonValue.JsonNull) {
return null;
}
if (value instanceof JsonValue.JsonNumber n) {
Expand All @@ -120,7 +120,7 @@ public static BigDecimal toBigDecimal(JsonValue value) {
}

public static BigInteger toBigInteger(JsonValue value) {
if (value instanceof JsonValue.JsonNull) {
if (value == null || value instanceof JsonValue.JsonNull) {
return null;
}
if (value instanceof JsonValue.JsonNumber n) {
Expand All @@ -130,7 +130,7 @@ public static BigInteger toBigInteger(JsonValue value) {
}

public static <E extends Enum<E>> E toEnum(JsonValue value, Class<E> enumClass) {
if (value instanceof JsonValue.JsonNull) {
if (value == null || value instanceof JsonValue.JsonNull) {
return null;
}
if (value instanceof JsonValue.JsonString s) {
Expand All @@ -140,7 +140,7 @@ public static <E extends Enum<E>> E toEnum(JsonValue value, Class<E> enumClass)
}

public static <E extends Enum<E>> E toEnum(JsonValue value, Map<String, E> lookup) {
if (value instanceof JsonValue.JsonNull) {
if (value == null || value instanceof JsonValue.JsonNull) {
return null;
}
if (value instanceof JsonValue.JsonString s) {
Expand All @@ -154,7 +154,7 @@ public static <E extends Enum<E>> E toEnum(JsonValue value, Map<String, E> looku
}

public static <T> List<T> toList(JsonValue value, Function<JsonValue, T> elementMapper) {
if (value instanceof JsonValue.JsonNull) {
if (value == null || value instanceof JsonValue.JsonNull) {
return null;
}
if (value instanceof JsonValue.JsonArray arr) {
Expand All @@ -168,7 +168,7 @@ public static <T> List<T> toList(JsonValue value, Function<JsonValue, T> element
}

public static <V> Map<String, V> toMap(JsonValue value, Function<JsonValue, V> valueMapper) {
if (value instanceof JsonValue.JsonNull) {
if (value == null || value instanceof JsonValue.JsonNull) {
return null;
}
if (value instanceof JsonValue.JsonObject obj) {
Expand Down
Loading