From e7ddbad14925be384af4b7eba068921d2e099b3d Mon Sep 17 00:00:00 2001 From: Riley Park Date: Wed, 20 Oct 2021 16:37:29 -0700 Subject: [PATCH] fix #447 by allowing deserializeOr to return null --- .../text/serializer/gson/GsonComponentSerializerImpl.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/text-serializer-gson/src/main/java/net/kyori/adventure/text/serializer/gson/GsonComponentSerializerImpl.java b/text-serializer-gson/src/main/java/net/kyori/adventure/text/serializer/gson/GsonComponentSerializerImpl.java index 12fe1ea38..e36f0dad3 100644 --- a/text-serializer-gson/src/main/java/net/kyori/adventure/text/serializer/gson/GsonComponentSerializerImpl.java +++ b/text-serializer-gson/src/main/java/net/kyori/adventure/text/serializer/gson/GsonComponentSerializerImpl.java @@ -86,6 +86,14 @@ static final class Instances { return component; } + @Override + public @Nullable Component deserializeOr(final @Nullable String input, final @Nullable Component fallback) { + if (input == null) return fallback; + final Component component = this.serializer().fromJson(input, Component.class); + if (component == null) return fallback; + return component; + } + @Override public @NotNull String serialize(final @NotNull Component component) { return this.serializer().toJson(component);