Skip to content

Commit d2968db

Browse files
committed
fix: deserializing commented node in RecordDeserializer
1 parent 91c321c commit d2968db

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

core/src/main/java/com/github/siroshun09/configapi/core/serialization/record/RecordDeserializer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.github.siroshun09.configapi.core.node.BooleanArray;
2020
import com.github.siroshun09.configapi.core.node.BooleanValue;
2121
import com.github.siroshun09.configapi.core.node.ByteArray;
22+
import com.github.siroshun09.configapi.core.node.CommentedNode;
2223
import com.github.siroshun09.configapi.core.node.DoubleArray;
2324
import com.github.siroshun09.configapi.core.node.EnumValue;
2425
import com.github.siroshun09.configapi.core.node.FloatArray;
@@ -293,7 +294,9 @@ private Object processInlinedRecord(@NotNull RecordComponent parent, @NotNull Cl
293294
@SuppressWarnings("unchecked")
294295
private @Nullable Object deserializeNode(@NotNull Node<?> node, @NotNull Class<?> clazz,
295296
@Nullable Object defaultObject) {
296-
if (clazz == boolean.class || clazz == Boolean.class) {
297+
if (node instanceof CommentedNode<?> commentedNode) {
298+
return this.deserializeNode(commentedNode.node(), clazz, defaultObject);
299+
} else if (clazz == boolean.class || clazz == Boolean.class) {
297300
return node instanceof BooleanValue booleanValue ? booleanValue.value() : defaultObject;
298301
} else if (clazz == String.class) {
299302
return node instanceof StringValue stringValue ? stringValue.asString() : defaultObject;

core/src/test/java/com/github/siroshun09/configapi/core/serialization/record/RecordDeserializerTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616

1717
package com.github.siroshun09.configapi.core.serialization.record;
1818

19+
import com.github.siroshun09.configapi.core.comment.SimpleComment;
20+
import com.github.siroshun09.configapi.core.node.CommentableNode;
1921
import com.github.siroshun09.configapi.core.node.MapNode;
22+
import com.github.siroshun09.configapi.core.node.StringValue;
2023
import com.github.siroshun09.configapi.core.serialization.SerializationException;
2124
import com.github.siroshun09.configapi.core.serialization.key.KeyGenerator;
2225
import com.github.siroshun09.configapi.test.shared.data.Samples;
@@ -58,4 +61,18 @@ void testCustomObjectAndCustomKeyGenerator() {
5861
var deserializer = RecordDeserializer.builder(Samples.UUIDRecord.class).addDeserializer(UUID.class, node -> UUID.fromString(node.value().toString())).keyGenerator(KeyGenerator.CAMEL_TO_KEBAB).build();
5962
Assertions.assertEquals(Samples.uuidRecord(), deserializer.deserialize(Samples.uuidRecordMapNode()));
6063
}
64+
65+
@Test
66+
void testDeserializingCommentedNode() {
67+
var deserializer = RecordDeserializer.create(SimpleRecord.class);
68+
69+
var mapNode = MapNode.create();
70+
mapNode.set("value", CommentableNode.withComment(StringValue.fromString("value"), SimpleComment.create("comment")));
71+
72+
var actual = deserializer.deserialize(mapNode);
73+
Assertions.assertEquals("value", actual.value());
74+
}
75+
76+
private record SimpleRecord(String value) {
77+
}
6178
}

0 commit comments

Comments
 (0)