mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
34 lines
1.3 KiB
Java
34 lines
1.3 KiB
Java
|
|
package com.chameleonvision.vision.camera;
|
||
|
|
|
||
|
|
import com.chameleonvision.vision.Pipeline;
|
||
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||
|
|
import com.fasterxml.jackson.databind.type.MapType;
|
||
|
|
import com.fasterxml.jackson.databind.type.TypeFactory;
|
||
|
|
import com.google.gson.*;
|
||
|
|
|
||
|
|
import java.lang.reflect.Type;
|
||
|
|
import java.util.HashMap;
|
||
|
|
|
||
|
|
public class CameraDeserializer implements JsonDeserializer<Camera> {
|
||
|
|
@Override
|
||
|
|
public Camera deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||
|
|
var jsonObj = jsonElement.getAsJsonObject();
|
||
|
|
var camFOV = jsonObj.get("FOV").getAsDouble();
|
||
|
|
var camName = jsonObj.get("name").getAsString();
|
||
|
|
|
||
|
|
var pipelines = jsonObj.get("pipelines");
|
||
|
|
HashMap<Integer, Pipeline> actualPipelines = new HashMap<>();
|
||
|
|
ObjectMapper mapper = new ObjectMapper();
|
||
|
|
TypeFactory typeFactory = mapper.getTypeFactory();
|
||
|
|
MapType mapType = typeFactory.constructMapType(HashMap.class, Integer.class, Pipeline.class);
|
||
|
|
try {
|
||
|
|
actualPipelines = mapper.readValue(pipelines.toString(), mapType);
|
||
|
|
} catch (JsonProcessingException e) {
|
||
|
|
e.printStackTrace();
|
||
|
|
}
|
||
|
|
|
||
|
|
return actualPipelines != null ? new Camera(camName, camFOV, actualPipelines) : new Camera(camName, camFOV);
|
||
|
|
}
|
||
|
|
}
|