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

2.10.1 KSP generated adapters have trouble with generic typealiases when there is a default value #201

Closed
daviddenton opened this issue Jan 18, 2023 · 3 comments · Fixed by #202

Comments

@daviddenton
Copy link
Contributor

Another edgecase 😄 .

Given the below:

typealias FooBar = List<String>

@JsonSerializable
data class Goo(
    val Item: FooBar? = null
)

The generated "fromJson" method contains:

 // Reflectively invoke the synthetic defaults constructor
      @Suppress("UNCHECKED_CAST")
      val localConstructor: Constructor<Goo> = this.defaultConstructor ?:
          Goo::class.java.getDeclaredConstructor(
            FooBar::class.java,   // should be:  List::class.java
            Int::class.javaPrimitiveType,
            DefaultConstructorMarker::class.java
          ).also { this.defaultConstructor = it }
      localConstructor.newInstance(
          item,
          mask,
          /* DefaultConstructorMarker */ null
      )
    }

Error message is: Only classes are allowed on the left hand side of a class literal

ansman added a commit that referenced this issue Jan 18, 2023
If a data class contained a type alias and default values, then the
lookup of the default constructor would contain invalid references to
the typealias.

This fixes #201
ansman added a commit that referenced this issue Jan 18, 2023
If a data class contained a type alias and default values, then the
lookup of the default constructor would contain invalid references to
the typealias.

This fixes #201
@ansman
Copy link
Owner

ansman commented Jan 18, 2023

A fix was just released in 2.10.2.

@daviddenton
Copy link
Contributor Author

This now works like a charm! Thank you so much for the quick turnaround. 😄

@ansman
Copy link
Owner

ansman commented Jan 19, 2023

No problem, let me know if there are any other issues 🙏

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

Successfully merging a pull request may close this issue.

2 participants