spring-projects / spring-projects/spring-graphql

@BatchMapping does not support kotlin collection whose element type is interface.

Open
#454 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
1.6k
Forks
336
PR merge metrics
No merged PRs in 30d

Description

The annotation @BatchMapping requires method whose parameter is collection/list, eg

@BatchMapping
public Map<Child, Parent> manyToOne(List<Child> childObjects) {...} 

For java, it's OK.

Howerver, for kotlin, it's not OK

@BatchMapping
fun manyToOne(childObjects: List<Child>): Map<Child, Parent> =...

Because kotlin compiler generates the parameter type as kotlin.collections.List/kotlin.collections.Collection, not java.util.List/java.util.Collection

Now, my workaround is: Explicitly use java.util.List in kotlin, this will cause warning of Intellij.


SpringBoot version:
2.7.0

Example code:
Line 36 and 46 of here

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lines 36 and 46 of BookController.kt in the linked Jimmer example and compare the Kotlin collection signatures with the Java @BatchMapping example. Trace how @BatchMapping recognizes the parameter type; done means Kotlin kotlin.collections.List or Collection parameters with interface element types work without explicitly using java.util.List.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, java, kotlin, spring-boot
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.