Search in sources :

Example 1 with JsonpDeserializable

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());
}
Also used : JsonpDeserializable(org.opensearch.client.json.JsonpDeserializable) ScanResult(io.github.classgraph.ScanResult) ClassInfoList(io.github.classgraph.ClassInfoList) ClassGraph(io.github.classgraph.ClassGraph) StringReader(java.io.StringReader) ClassInfo(io.github.classgraph.ClassInfo) JsonParser(jakarta.json.stream.JsonParser) Test(org.junit.Test)

Aggregations

ClassGraph (io.github.classgraph.ClassGraph)1 ClassInfo (io.github.classgraph.ClassInfo)1 ClassInfoList (io.github.classgraph.ClassInfoList)1 ScanResult (io.github.classgraph.ScanResult)1 JsonParser (jakarta.json.stream.JsonParser)1 StringReader (java.io.StringReader)1 Test (org.junit.Test)1 JsonpDeserializable (org.opensearch.client.json.JsonpDeserializable)1