Skip to content

Commit

Permalink
[endec] clearer error message on EdmElement#asMap, return default val…
Browse files Browse the repository at this point in the history
…ue in EdmMap#getWithErrors if key is not present
  • Loading branch information
gliscowo committed Feb 16, 2024
1 parent 521a11d commit f2eb997
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Object unwrap() {

public EdmMap asMap() {
if(this.type != Type.MAP) {
throw new IllegalStateException("Given Element is not a Map Type: " + this);
throw new IllegalStateException("Cannot cast EDM element of type " + this.type + " to MAP");
}

return new EdmMap(this.cast());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public final class EdmMap extends EdmElement<Map<String, EdmElement<?>>> impleme

@Override
public <T> T getWithErrors(@NotNull KeyedEndec<T> key) {
if (!this.has(key)) return key.defaultValue();
return key.endec().decodeFully(EdmDeserializer::of, this.value().get(key.key()));
}

Expand Down

0 comments on commit f2eb997

Please sign in to comment.