use of org.opensearch.client.json.JsonpDeserializable in project opensearch-java by opensearch-project.
the class SerializationTest method loadAllDeserializers.
@Test
public void loadAllDeserializers() throws Exception {
ScanResult scan = new ClassGraph().acceptPackages("org.opensearch.client").enableAnnotationInfo().enableFieldInfo().scan();
ClassInfoList withAnnotation = scan.getClassesWithAnnotation(JsonpDeserializable.class.getName());
assertFalse("No JsonpDeserializable classes", withAnnotation.isEmpty());
for (ClassInfo info : withAnnotation) {
Class<?> clazz = Class.forName(info.getName());
JsonpDeserializer<?> deserializer = JsonpMapperBase.findDeserializer(clazz);
assertNotNull(deserializer);
// Deserialize something dummy to resolve lazy deserializers
JsonParser parser = mapper.jsonProvider().createParser(new StringReader("-"));
assertThrows(JsonParsingException.class, () -> deserializer.deserialize(parser, mapper));
}
// Check that all classes that have a _DESERIALIZER field also have the annotation
ClassInfoList withDeserializer = scan.getAllClasses().filter((c) -> c.hasDeclaredField("_DESERIALIZER"));
assertFalse("No classes with a _DESERIALIZER field", withDeserializer.isEmpty());
// Disabled for now, empty response classes still need a deserializer object
// e.g. ExistsIndexTemplateResponse, PingResponse, ExistsResponse, ExistsAliasResponse
//
// Set<String> annotationNames = withAnnotation.stream().map(c -> c.getName()).collect(Collectors.toSet());
// Set<String> withFieldNames = withDeserializer.stream().map(c -> c.getName()).collect(Collectors.toSet());
//
// withFieldNames.removeAll(annotationNames);
//
// assertFalse("Some classes with the field but not the annotation: " + withFieldNames, !withFieldNames.isEmpty());
}
Aggregations