From 75c76743f83b8dd026b2cdfd6f5cce5ab14e2b74 Mon Sep 17 00:00:00 2001 From: Vankka Date: Thu, 7 Sep 2023 17:42:04 +0300 Subject: [PATCH] Attempt to add double quotes to PatternSerializer --- .../config/configurate/serializer/PatternSerializer.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/discordsrv/common/config/configurate/serializer/PatternSerializer.java b/common/src/main/java/com/discordsrv/common/config/configurate/serializer/PatternSerializer.java index 0f2450a0..c8a35716 100644 --- a/common/src/main/java/com/discordsrv/common/config/configurate/serializer/PatternSerializer.java +++ b/common/src/main/java/com/discordsrv/common/config/configurate/serializer/PatternSerializer.java @@ -18,10 +18,13 @@ package com.discordsrv.common.config.configurate.serializer; +import org.apache.commons.lang3.StringUtils; import org.checkerframework.checker.nullness.qual.Nullable; import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.serialize.SerializationException; import org.spongepowered.configurate.serialize.TypeSerializer; +import org.spongepowered.configurate.yaml.ScalarStyle; +import org.spongepowered.configurate.yaml.YamlConfigurationLoader; import java.lang.reflect.Type; import java.util.regex.Pattern; @@ -31,11 +34,12 @@ public class PatternSerializer implements TypeSerializer { @Override public Pattern deserialize(Type type, ConfigurationNode node) { String pattern = node != null ? node.getString() : null; - return pattern != null ? Pattern.compile(pattern) : null; + return StringUtils.isNotEmpty(pattern) ? Pattern.compile(pattern) : null; } @Override public void serialize(Type type, @Nullable Pattern obj, ConfigurationNode node) throws SerializationException { - node.set(obj != null ? obj.pattern() : null); + node = node.hint(YamlConfigurationLoader.SCALAR_STYLE, ScalarStyle.DOUBLE_QUOTED); + node.raw(obj != null ? obj.pattern() : null); } }