mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27:37 +00:00
- Fix NH bug & Gson not liking LocalDateTime
This commit is contained in:
parent
e70a01868d
commit
c2206d0079
@ -7,6 +7,9 @@ import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import dev.plex.util.adapter.LocalDateTimeAdapter;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@ -41,11 +44,11 @@ public class Punishment
|
||||
|
||||
public String toJSON()
|
||||
{
|
||||
return new Gson().toJson(this);
|
||||
return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeAdapter()).create().toJson(this);
|
||||
}
|
||||
|
||||
public static Punishment fromJson(String json)
|
||||
{
|
||||
return new Gson().fromJson(json, Punishment.class);
|
||||
return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeAdapter()).create().fromJson(json, Punishment.class);
|
||||
}
|
||||
}
|
||||
|
@ -75,6 +75,12 @@ public class MojangUtils
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return names.entrySet().stream().sorted(Map.Entry.comparingByValue()).collect(Collectors.toList());
|
||||
return names.entrySet().stream().sorted(Map.Entry.comparingByValue((o1, o2) -> {
|
||||
if (o1 == null || o2 == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return o1.compareTo(o2);
|
||||
})).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package dev.plex.util.adapter;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class LocalDateTimeAdapter implements JsonSerializer<LocalDateTime>
|
||||
{
|
||||
@Override
|
||||
public JsonElement serialize(LocalDateTime src, Type typeOfSrc, JsonSerializationContext context)
|
||||
{
|
||||
return new JsonPrimitive(src.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user