47degrees / helios

A purely functional JSON library for Kotlin built on Λrrow
https://47degrees.github.io/helios/
Apache License 2.0
169 stars 22 forks source link

Safely generate encoders for product type #24

Open AdrianRaFo opened 5 years ago

AdrianRaFo commented 5 years ago

Related to https://github.com/47deg/helios/pull/13

There is a problem lied with the meta compiler. More specifically when generating encoders/decoders for product types that depend on other encoders/decoders such as List<String> or Option< List<String>>.

@json data class Friend(val _id: String, val tags: List<String>)
@json data class SpecialFriend(val _id: String, val errorOrTags: Option< List<String>>)

We need to investigate how to safely generate encoders for these product types.

nomisRev commented 5 years ago

The same technique as Arrow-generic will have to be applied.

If a Kind<F, A> is detected than something like F.encoder(A.encoder()) should be generated. Taking arity into account.

AFAIK we can currently not verify if F.encoder exists so we cannot provide a better error message and will fallback to the technique we use in arrow-generic.

Swing by Slack for any questions :)