mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
added json serializer and de serializer
This commit is contained in:
@@ -57,22 +57,10 @@ public class VisionManager {
|
||||
// Gson gson = new GsonBuilder().registerTypeAdapter(USBCameraProcess.class, new CameraDeserializer());
|
||||
// }
|
||||
}
|
||||
})
|
||||
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
public void PipelineSerializer(List<CVPipelineSettings> list, Path path) throws IOException {
|
||||
File pipelineFile = new File(path.toString());
|
||||
ObjectMapper objectMapper = new ObjectMapper().enableDefaultTyping();
|
||||
objectMapper.writeValue(pipelineFile,list);
|
||||
}
|
||||
|
||||
public List<CVPipelineSettings> PipelineDESerializer(Path path) throws IOException {
|
||||
File pipelineFile = new File(path.toString());
|
||||
ObjectMapper objectMapper = new ObjectMapper().enableDefaultTyping();
|
||||
List<CVPipelineSettings> list = Arrays.asList(objectMapper.readValue(pipelineFile, CVPipelineSettings[].class));
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void initializeProcesses() {
|
||||
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package com.chameleonvision.util;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||
import com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator;
|
||||
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -22,4 +27,18 @@ public class FileHelper {
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void Serializer(Object object, Path path) throws IOException {
|
||||
File file = new File(path.toString());
|
||||
PolymorphicTypeValidator ptv = BasicPolymorphicTypeValidator.builder().allowIfBaseType(Object.class).build();
|
||||
ObjectMapper objectMapper = JsonMapper.builder().activateDefaultTyping(ptv, ObjectMapper.DefaultTyping.JAVA_LANG_OBJECT).build();
|
||||
objectMapper.writeValue(file,object);
|
||||
}
|
||||
|
||||
public static Object DeSerializer(Path path,Class<?> ref) throws IOException {
|
||||
File file = new File(path.toString());
|
||||
PolymorphicTypeValidator ptv = BasicPolymorphicTypeValidator.builder().allowIfBaseType(Object.class).build();
|
||||
ObjectMapper objectMapper = JsonMapper.builder().activateDefaultTyping(ptv, ObjectMapper.DefaultTyping.JAVA_LANG_OBJECT).build();
|
||||
Object o = objectMapper.readValue(file, ref);
|
||||
return o;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user