feat: implemented deserializer for IntVector2 and created a test for it
This commit is contained in:
@ -1,9 +1,13 @@
|
||||
package uulm.teamname.marvelous.gamelibrary;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import uulm.teamname.marvelous.gamelibrary.json.ingame.IntVector2Deserializer;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
/** Represents a 2d vector of integers. */
|
||||
@JsonDeserialize(using = IntVector2Deserializer.class)
|
||||
public class IntVector2 implements Serializable {
|
||||
private int x;
|
||||
private int y;
|
||||
|
@ -0,0 +1,24 @@
|
||||
package uulm.teamname.marvelous.gamelibrary.json.ingame;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.ObjectCodec;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class IntVector2Deserializer extends JsonDeserializer<IntVector2> {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Override
|
||||
public IntVector2 deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
||||
var values = mapper.readValue(p, Integer[].class);
|
||||
IntVector2 result = new IntVector2(values[0], values[1]);
|
||||
return result;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user