feat: optimized IntVector2Deserializer

This commit is contained in:
Yannik Bretschneider 2021-05-30 17:01:27 +02:00
parent d0829f3948
commit cb0f2cae13

View File

@ -12,13 +12,9 @@ import uulm.teamname.marvelous.gamelibrary.IntVector2;
import java.io.IOException; import java.io.IOException;
public class IntVector2Deserializer extends JsonDeserializer<IntVector2> { public class IntVector2Deserializer extends JsonDeserializer<IntVector2> {
// static so that no reinitializations are needed
private static final ObjectMapper mapper = new ObjectMapper();
@Override @Override
public IntVector2 deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { public IntVector2 deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
var values = mapper.readValue(p, Integer[].class); var values = p.readValueAs(Integer[].class);
IntVector2 result = new IntVector2(values[0], values[1]); IntVector2 result = new IntVector2(values[0], values[1]);
return result; return result;
} }