Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please point me on how to add new collection types (e.g. Vavr / Guava) #712

domdorn opened this issue Jun 4, 2020 · 5 comments


Copy link

domdorn commented Jun 4, 2020

I'm trying to add the collection types ( Option, List, Tuple, etc.) from the vavr-library, but can't seem to find where to plug them in (
I already figured out on how to make the Future type work here
but I'm a little lost on how to make the collections types work.
It would be great if you could point me in the right direction!

This is what I tried so far:

  1. I've already tried creating a io.swagger.v3.core.converter.ModelConverter but this leads to NPEs when swagger tries to clone the schema.
  2. I also tried SpringDocUtils.getConfig().replaceWithClass(io.vavr.control.Option.class, java.util.Optional.class); but this seems to be unable to handle generics.
  3. I tried to register the VavrModule with the ObjectMapper of SpringDoc/Swagger, but this also doesn't help ( Json.mapper().registerModule(new VavrModule()); )


Copy link

bnasslahsen commented Jun 4, 2020


For collections, i assume you already have registred Jackson VavrModule.
If you need to use the mapping of Java Collection instead of the one of Vavr Collection. You can declare in your application:

static {
			.replaceWithClass(io.vavr.collection.Set.class, java.util.Set.class)
			.replaceWithClass(io.vavr.collection.List.class, java.util.List.class)
			.replaceWithClass(io.vavr.collection.Map.class, java.util.Map.class);

For io.vavr.control.Option, you can use a custom ModelConverter, as it is not available on ModelResolver._isOptionalType is only supporting and java.util.Optional.
Here is a sample code for a ModelConverter.

public class VavrOptionSupportConverter implements ModelConverter {

public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context, Iterator<ModelConverter> chain) {
	JavaType javaType = Json.mapper().constructType(annotatedType.getType());
	if (javaType != null) {
		Class<?> cls = javaType.getRawClass();
		if (io.vavr.control.Option.class.equals(cls)){
			annotatedType = new AnnotatedType()
			return this.resolve(annotatedType, context, chain);
	return (chain.hasNext()) ?, context, chain) : null;


Copy link

domdorn commented Jun 9, 2020

perfect, thank you @bnasslahsen ! While the replaceWithClass didn't had the intended result (e.g. it lost type information and thus all collections became untyped arrays), your code of the ModelConverter works good enough so I could also implement it for the collection types. Will create a blog post with the full code soon and give attribution to you @bnasslahsen !

Copy link

ghost commented Nov 2, 2021

Hi @domdorn, did you write a blog post for collection types. I am also facing the same problem so it would be a great help for me

Copy link

ghost commented Nov 2, 2021

hi @domdorn found your gist here

thanks, it helped.

Commenting it here so that others will be able to find it easily

Copy link

domdorn commented Nov 2, 2021

The post is supposed to be this one:
but apparently the github-gist plugin for wordpress fails for some reason.. anyway, you've found the right gist :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

2 participants