I am working on a project where I need to generate JSON schemas for all of the objects that are returned from my API.
I am given a String such as:
"com.example.CustomListing<MyClass>"
My goal is to create a schema for CustomListing
and insert a $ref
to MyClass
in all the places it is used in CustomListing
.
Jackson offers a way to create schemas from generics here but I need to have Class object for that generic type.
I can create a generic Class object using a method here but it requires me to know the type ahead of time, which I do not.
How can I get a Class<CustomListing<MyClass>>
when I am only given the String "com.example.CustomListing<MyClass>"
?
EDIT: I am creating these schemas in a JavaDoc doclet, so I am working at compile time, hence the limitations.
I think I have found a direction to go for the solution. I am using ObjectMapper
from Jackson which allows me to configure modules to process any given type. I believe I can register some to deal with a generic (such as <T>
) and it would know that in this case <T>
would be referencing MyClass
instead and insert the $ref
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.