Json serializer writes `ObjectMap` incorrectly
Blockzilla101 opened this issue · 1 comments
Blockzilla101 commented
Version: master-SNAPSHOT
Description: Trying write an ObjectMap
with its key set to Team
writes the team as a string instead of using its seralizer to write the team id.
Steps to reproduce: Run the following code:
public class Foo {
public ObjectMap<Team, Integer> bar = new ObjectMap<>();
}
var foo = new Foo();
foo.bar.put(Team.sharded, 0);
JsonIO.read(Foo.class, JsonIO.write(foo));
foo
looks like this after serializing: {bar:{sharded:0}}
Logs:
[10-02-2022 11:03:48] [E] arc.util.serialization.SerializationException: Serialization trace:
{}.bar
bar (bomberman.MapLoader$Foo)
at arc.util.serialization.Json.readFields(Json.java:904)
at arc.util.serialization.Json.readValue(Json.java:1077)
at arc.util.serialization.Json.readValue(Json.java:980)
at arc.util.serialization.Json.fromJson(Json.java:821)
at mindustry.io.JsonIO.read(JsonIO.java:61)
at bomberman.MapLoader.load(MapLoader.java:35)
at plugin.BomberMan.lambda$reloadMaps$12(BomberMan.java:186)
at mindustry.core.World.loadMap(World.java:340)
at mindustry.core.World.loadMap(World.java:334)
at mindustry.server.ServerControl.lambda$registerCommands$30(ServerControl.java:392)
at arc.util.CommandHandler.lambda$register$2(CommandHandler.java:128)
at arc.util.CommandHandler.handleMessage(CommandHandler.java:85)
at arc.util.CommandHandler.handleMessage(CommandHandler.java:29)
at mindustry.server.ServerControl.lambda$setup$6(ServerControl.java:156)
at arc.util.TaskQueue.run(TaskQueue.java:17)
at arc.backend.headless.HeadlessApplication.mainLoop(HeadlessApplication.java:81)
at arc.backend.headless.HeadlessApplication$1.run(HeadlessApplication.java:52)
Caused by: java.lang.NumberFormatException: For input string: "sharded"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
at java.base/java.lang.Integer.parseInt(Integer.java:668)
at java.base/java.lang.Integer.parseInt(Integer.java:786)
at arc.util.serialization.JsonValue.asInt(JsonValue.java:261)
at mindustry.io.JsonIO$8.read(JsonIO.java:172)
at mindustry.io.JsonIO$8.read(JsonIO.java:164)
at arc.util.serialization.Json.readValue(Json.java:1084)
at arc.util.serialization.Json.readValue(Json.java:980)
at arc.util.serialization.Json.readValue(Json.java:1034)
at arc.util.serialization.Json.readFields(Json.java:897)
... 16 more
Anuken commented
JSON keys must always be strings. Numbers cannot be keys.