baeldung-articles : BAEL-5937 (#15922)

Create JavaType From Class with Jackson (commit).
This commit is contained in:
Diegom203 2024-02-19 18:24:35 -08:00 committed by GitHub
parent bd36eddeca
commit d4f8b4ff66
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,38 @@
package com.baeldung.javatypefromclassinjava;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;
public class JavaTypeFromClassUnitTest {
@Test
public void givenGenericClass_whenCreatingJavaType_thenJavaTypeNotNull() {
Class<?> myClass = MyGenericClass.class;
JavaType javaType = TypeFactory.defaultInstance().constructType(myClass);
assertNotNull(javaType);
}
@Test
public void givenParametricType_whenCreatingJavaType_thenJavaTypeNotNull() {
Class<?> containerClass = Container.class;
Class<?> elementType = String.class;
JavaType javaType = TypeFactory.defaultInstance().constructParametricType(containerClass, elementType);
assertNotNull(javaType);
}
static class MyGenericClass<T> {
// Class implementation
}
static class Container<T> {
// Class implementation
}
}