diff --git a/core/src/main/java/com/github/siroshun09/configapi/core/node/MapNode.java b/core/src/main/java/com/github/siroshun09/configapi/core/node/MapNode.java index f9a0ea26..b6033d7a 100644 --- a/core/src/main/java/com/github/siroshun09/configapi/core/node/MapNode.java +++ b/core/src/main/java/com/github/siroshun09/configapi/core/node/MapNode.java @@ -294,7 +294,7 @@ public sealed interface MapNode extends CommentableNode>> pe * @return the {@link String} to which the specified key is mapped, or the specified value if the key is not mapped to {@link StringValue} */ default @NotNull String getString(@NotNull Object key, @NotNull String def) { - return this.raw(key) instanceof StringValue value ? value.asString() : def; + return this.raw(key) instanceof StringRepresentable value ? value.asString() : def; } /** @@ -304,7 +304,7 @@ public sealed interface MapNode extends CommentableNode>> pe * @return the {@link String} to which the specified key is mapped, or {@code null} if the key is not mapped to {@link StringValue} */ default @Nullable String getStringOrNull(@NotNull Object key) { - return this.raw(key) instanceof StringValue value ? value.asString() : null; + return this.raw(key) instanceof StringRepresentable value ? value.asString() : null; } /** diff --git a/core/src/test/java/com/github/siroshun09/configapi/core/node/MapNodeTest.java b/core/src/test/java/com/github/siroshun09/configapi/core/node/MapNodeTest.java index 9803385d..10a0c5ae 100644 --- a/core/src/test/java/com/github/siroshun09/configapi/core/node/MapNodeTest.java +++ b/core/src/test/java/com/github/siroshun09/configapi/core/node/MapNodeTest.java @@ -184,6 +184,16 @@ protected Stream> nodeTestCases() { assertSame(COMMENT, initial.getComment()); assertSame(COMMENT, view.getComment()); } + ), + nodeTest( + "MapNode#getString(String)", + MapNode.create(Map.of("a", "b", 1, 2)), + node -> { + assertEquals("b", node.getString("a")); + assertEquals("2", node.getString(1)); + assertEquals("", node.getString("unknown")); + assertEquals("default", node.getString("unknown", "default")); + } ) ); }