blob: 5ab3dfd9e76084f13284ad740fdba2dc54cb0e03 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
package moe.ymc.acron.common;
import com.google.gson.*;
import com.google.gson.annotations.SerializedName;
import java.lang.reflect.Type;
public record Vec2f(@SerializedName("x") float x,
@SerializedName("y") float y) {
public static class Vec2fDeserializer implements JsonDeserializer<Vec2f> {
@Override
public Vec2f deserialize(JsonElement json,
Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
final JsonObject object = json.getAsJsonObject();
final float x = object.has("x") ?
object.get("x").getAsFloat() :
0.0f;
final float y = object.has("y") ?
object.get("y").getAsFloat() :
0.0f;
return new Vec2f(x, y);
}
}
}
|