Skip to content

Commit

Permalink
Adjust optional handling to allow for checking if value is not a inst…
Browse files Browse the repository at this point in the history
…ance of Optional

- Handling Optional reads similar to Json and NBT if need be
  • Loading branch information
Dragon-Seeker committed Dec 20, 2023
1 parent 673760d commit 908f8b4
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -52,4 +55,18 @@ public boolean readBoolean() {

return super.readBoolean();
}


@Override
public <V> Optional<V> readOptional(Endec<V> 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));
}
}
}

0 comments on commit 908f8b4

Please sign in to comment.