From 908f8b48de9ad31c425ab8f9d1bf3c71b284e86d Mon Sep 17 00:00:00 2001 From: Dragon-Seeker Date: Wed, 20 Dec 2023 16:54:51 -0600 Subject: [PATCH] Adjust optional handling to allow for checking if value is not a instance of Optional - Handling Optional reads similar to Json and NBT if need be --- .../format/edm/LenientEdmDeserializer.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/io/wispforest/owo/serialization/format/edm/LenientEdmDeserializer.java b/src/main/java/io/wispforest/owo/serialization/format/edm/LenientEdmDeserializer.java index 9c40f0a2..e2c1a331 100644 --- a/src/main/java/io/wispforest/owo/serialization/format/edm/LenientEdmDeserializer.java +++ b/src/main/java/io/wispforest/owo/serialization/format/edm/LenientEdmDeserializer.java @@ -1,7 +1,10 @@ package io.wispforest.owo.serialization.format.edm; +import io.wispforest.owo.serialization.Endec; import io.wispforest.owo.serialization.SerializationAttribute; +import java.util.Optional; + public class LenientEdmDeserializer extends EdmDeserializer { public LenientEdmDeserializer(EdmElement serialized, SerializationAttribute... extraAttributes) { @@ -52,4 +55,18 @@ public boolean readBoolean() { return super.readBoolean(); } + + + @Override + public Optional readOptional(Endec endec) { + var edmElement = this.getValue(); + + if(edmElement == null){ + return Optional.empty(); + } else if(edmElement.value() instanceof Optional){ + return super.readOptional(endec); + } else { + return Optional.of(endec.decode(this)); + } + } }