Fix MailMessageSerializer not handling null UUIDs (#4314)

This commit is contained in:
Josh Roy 2021-07-03 19:32:34 -04:00 committed by GitHub
parent 7e25570344
commit 6535edf4e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,18 +7,19 @@ import org.spongepowered.configurate.serialize.SerializationException;
import org.spongepowered.configurate.serialize.TypeSerializer;
import java.lang.reflect.Type;
import java.util.Objects;
import java.util.UUID;
public class MailMessageSerializer implements TypeSerializer<MailMessage> {
@Override
public MailMessage deserialize(Type type, ConfigurationNode node) throws SerializationException {
final boolean legacy = node.node("legacy").getBoolean(true);
final String rawUuid = node.node("sender-uuid").getString();
final String uuid = (rawUuid == null || rawUuid.equals("null")) ? null : rawUuid;
return new MailMessage(node.node("read").getBoolean(false),
legacy,
!legacy ? node.node("sender-name").getString() : null,
!legacy ? UUID.fromString(Objects.requireNonNull(node.node("sender-uuid").getString())) : null,
uuid == null ? null : UUID.fromString(uuid),
!legacy ? node.node("timestamp").getLong() : 0L,
!legacy ? node.node("expire").getLong() : 0L,
node.node("message").getString());
@ -36,7 +37,7 @@ public class MailMessageSerializer implements TypeSerializer<MailMessage> {
node.node("message").set(String.class, obj.getMessage());
if (!obj.isLegacy()) {
node.node("sender-name").set(String.class, obj.getSenderUsername());
node.node("sender-uuid").set(String.class, obj.getSenderUUID().toString());
node.node("sender-uuid").set(String.class, obj.getSenderUUID() == null ? "null" : obj.getSenderUUID().toString());
node.node("timestamp").set(Long.class, obj.getTimeSent());
node.node("expire").set(Long.class, obj.getTimeExpire());
}