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

Support mapping custom scalars to generic classes with type parameters. #3243

Open
martinbonnin opened this issue Jul 15, 2021 · 1 comment

Comments

@martinbonnin
Copy link
Contributor

martinbonnin commented Jul 15, 2021

Right now, we can map custom scalars to Kotlin classes using a Gradle configuration:

apollo {
    customTypeMapping.set(mapOf(
    "Date" to "java.util.Date"
  ))
}

This doesn't work anymore with generic types:

apollo {
    customTypeMapping.set(mapOf(
    "Json" to "kotlin.collection.Map<String, Any?>"
  ))
}

One simple workaround is to use a type alias:

typealias JsonScalar = Map<String, Any?>

But that's adding a level of indirection. Is there value in adding generics support?

@BoD
Copy link
Contributor

BoD commented Sep 24, 2024

In #6158 we now accept the simple cases:

  • com.example.Type / com.example.Type?
  • com.example.Type<com.example.Type1, com.example.Type2>
  • common Kotlin and Java types like String, Map, etc. don't need to include the package name

More complex cases like Type<Type1<Type2>>, Type<*> or Type<out Type1> aren't covered. They would need a more advanced Kotlin/Java parser (maybe that could make a nice contribution to KotlinPoet/JavaPoet?).

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

No branches or pull requests

2 participants