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

Sealed class support #86

Open
Octogonapus opened this issue Jul 8, 2019 · 0 comments
Open

Sealed class support #86

Octogonapus opened this issue Jul 8, 2019 · 0 comments
Labels
meta Related with the annotation processor

Comments

@Octogonapus
Copy link
Collaborator

The annotation processor generates invalid code for sealed classes.

This code:

@json
sealed class LinkType {
    object Rotary : LinkType()
    object Prismatic : LinkType()

    companion object
}

Generates this:

fun LinkType.toJson(): Json = JsObject(mapOf())

fun Json.Companion.toLinkType(value: Json): Either<DecodingError, LinkType> =
  Either.applicative<DecodingError>().map(
	
,  {  ->
  LinkType()
}).fix()



fun LinkType.Companion.encoder() = object : Encoder<LinkType> {
  override fun LinkType.encode(): Json = this.toJson()
}

fun LinkType.Companion.decoder() = object : Decoder<LinkType> {
  override fun decode(value: Json): Either<DecodingError, LinkType> =
    Json.toLinkType(value)
}

Apart from the issue with the call to map(), it's not possible to construct a LinkType because it is a sealed class.

@AdrianRaFo AdrianRaFo added New Type Support Support for a new type meta Related with the annotation processor and removed New Type Support Support for a new type labels Jul 12, 2019
@AdrianRaFo AdrianRaFo added this to To do in Release 0.3.0 Jul 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta Related with the annotation processor
Projects
Release 0.3.0
  
To do
Development

No branches or pull requests

2 participants