Skip to content

Commit

Permalink
Call unsetTempRestoreNewLine on every block start (closes #5)
Browse files Browse the repository at this point in the history
  • Loading branch information
hevav committed Oct 21, 2023
1 parent 6789cf0 commit 50b1508
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public YamlReader(BufferedReader reader) {
@SuppressFBWarnings("SA_FIELD_SELF_COMPARISON")
public void readSerializableObject(@Nullable Field owner, Object holder, Class<?> clazz) {
synchronized (this) {
this.unsetTempRestoreNewLine();
this.readBeginSerializableObject(owner);
Field[] nodes = clazz.getDeclaredFields();
if (nodes.length != 0) {
Expand Down Expand Up @@ -531,6 +532,7 @@ private <C extends Collection<Object>> C readCollectionFromMarker(@Nullable Fiel
marker = AbstractReader.NEW_LINE;
}

this.unsetTempRestoreNewLine();
switch (marker) {
case '[': {
char nextMarker = this.readRawIgnoreEmptyAndNewLines();
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/net/elytrium/serializer/SerializerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ void testConfig() throws IOException {
Assertions.assertEquals(3, settings.listOfString2ObjectMap.size());
Assertions.assertEquals(3, settings.chaosMapList.size());
Assertions.assertEquals(2, settings.chaosMap.size());
Assertions.assertEquals(1, settings.listSerializableMap.size());
Assertions.assertEquals(HashMap.class, settings.int2StringMap.getClass());
Assertions.assertEquals(Int2ObjectLinkedOpenHashMap.class, settings.int2StringMapFastUtil.getClass());
Assertions.assertEquals(Int2ObjectLinkedOpenHashMap.class, settings.int2StringMapFastUtil2.getClass());
Expand Down Expand Up @@ -383,6 +384,8 @@ public String deserialize(String from) {
"test-2", SerializerTest.map("test-2-1", Arrays.asList("element"))
);

public List<CustomSection> listSerializableMap = Arrays.asList(new CustomSection());

@Comment({
@CommentValue("PREPEND comment Line 1"),
@CommentValue("PREPEND comment Line 2")
Expand Down Expand Up @@ -572,6 +575,15 @@ public ExternalNestedClass(String name) {
}
}

public static class CustomSection {

public Map<String, String> stringStringMap = new LinkedHashMap<>();

public CustomSection() {
this.stringStringMap.put("key1", "value1");
}
}

public static class ExternalClassSerializer extends ClassSerializer<ExternalDeserializedClass, Map<String, Object>> {

@SuppressWarnings("unchecked")
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ chaos-map:
test-2:
test-2-1:
- "element"
list-serializable-map:
- string-string-map:
key1: "value1"
# PREPEND class comment
# PREPEND comment Line 1
# PREPEND comment Line 2
Expand Down

0 comments on commit 50b1508

Please sign in to comment.