We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Given this case classes:
@jsonDerive case class A[T](key1: Int, key2: T) @jsonDerive case class B( key1: Int, key2: Int, key3: Int, )
this compiles and works fine:
val a: A[B] = A(1, B(1, 2, 3)) a.toJson.fromJson[A[B]]
This however fails to compile:
val a: A[B] = A(1, B(1, 2, 3)) def foo[T](arg: A[T]) = { arg.toJson.fromJson[A[T]] //compilation error here } foo(a)
with the following error message
could not find implicit value for parameter encoder: zio.json.JsonEncoder[A[T]] arg.toJson.fromJson[A[T]]
I understand this is because at compilation time you can't tell if T has encoder....
T
Is there a way to have such generic code working with some custom encoders/decoders? How would I go about it?
The text was updated successfully, but these errors were encountered:
@artur-jablonski Have you tried if def foo[T: JsonEncoder](arg: A[T]) works for your case?
def foo[T: JsonEncoder](arg: A[T])
Sorry, something went wrong.
This fails to compile with the same error message as before
def foo[T: JsonEncoder](arg: A[T]) = { arg.toJson.fromJson[A[T]] }
No branches or pull requests
Given this case classes:
this compiles and works fine:
This however fails to compile:
with the following error message
I understand this is because at compilation time you can't tell if
T
has encoder....Is there a way to have such generic code working with some custom encoders/decoders? How would I go about it?
The text was updated successfully, but these errors were encountered: