Skip to content

Commit 50b1508

Browse files
committed
Call unsetTempRestoreNewLine on every block start (closes #5)
1 parent 6789cf0 commit 50b1508

3 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/main/java/net/elytrium/serializer/language/reader/YamlReader.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public YamlReader(BufferedReader reader) {
8484
@SuppressFBWarnings("SA_FIELD_SELF_COMPARISON")
8585
public void readSerializableObject(@Nullable Field owner, Object holder, Class<?> clazz) {
8686
synchronized (this) {
87+
this.unsetTempRestoreNewLine();
8788
this.readBeginSerializableObject(owner);
8889
Field[] nodes = clazz.getDeclaredFields();
8990
if (nodes.length != 0) {
@@ -531,6 +532,7 @@ private <C extends Collection<Object>> C readCollectionFromMarker(@Nullable Fiel
531532
marker = AbstractReader.NEW_LINE;
532533
}
533534

535+
this.unsetTempRestoreNewLine();
534536
switch (marker) {
535537
case '[': {
536538
char nextMarker = this.readRawIgnoreEmptyAndNewLines();

src/test/java/net/elytrium/serializer/SerializerTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ void testConfig() throws IOException {
147147
Assertions.assertEquals(3, settings.listOfString2ObjectMap.size());
148148
Assertions.assertEquals(3, settings.chaosMapList.size());
149149
Assertions.assertEquals(2, settings.chaosMap.size());
150+
Assertions.assertEquals(1, settings.listSerializableMap.size());
150151
Assertions.assertEquals(HashMap.class, settings.int2StringMap.getClass());
151152
Assertions.assertEquals(Int2ObjectLinkedOpenHashMap.class, settings.int2StringMapFastUtil.getClass());
152153
Assertions.assertEquals(Int2ObjectLinkedOpenHashMap.class, settings.int2StringMapFastUtil2.getClass());
@@ -383,6 +384,8 @@ public String deserialize(String from) {
383384
"test-2", SerializerTest.map("test-2-1", Arrays.asList("element"))
384385
);
385386

387+
public List<CustomSection> listSerializableMap = Arrays.asList(new CustomSection());
388+
386389
@Comment({
387390
@CommentValue("PREPEND comment Line 1"),
388391
@CommentValue("PREPEND comment Line 2")
@@ -572,6 +575,15 @@ public ExternalNestedClass(String name) {
572575
}
573576
}
574577

578+
public static class CustomSection {
579+
580+
public Map<String, String> stringStringMap = new LinkedHashMap<>();
581+
582+
public CustomSection() {
583+
this.stringStringMap.put("key1", "value1");
584+
}
585+
}
586+
575587
public static class ExternalClassSerializer extends ClassSerializer<ExternalDeserializedClass, Map<String, Object>> {
576588

577589
@SuppressWarnings("unchecked")

src/test/resources/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ chaos-map:
115115
test-2:
116116
test-2-1:
117117
- "element"
118+
list-serializable-map:
119+
- string-string-map:
120+
key1: "value1"
118121
# PREPEND class comment
119122
# PREPEND comment Line 1
120123
# PREPEND comment Line 2

0 commit comments

Comments
 (0)