[QUESTION] - Looking for some better way to encode or decode json. #6995
Replies: 2 comments 2 replies
-
I can't recall any reason that would have changed, but it has been several years since I looked at Argonaut. I would consider diffing the argonaut source code between those two http4s versions to see whether any implicits changed, and also look at which versions of argonaut were used to see whether its derivation changed. |
Beta Was this translation helpful? Give feedback.
-
Instead of defining implicit entity encoders for each case class and its variations, you could define a generic encoder for any case class that has a corresponding CodecJson. Here's an example implementation: import argonaut.Argonaut._ object JsonCodecs { Then, you can import the genericEntityEncoder and use it for any case class that has a corresponding CodecJson, without having to define additional implicit entity encoders: import org.http4s.EntityEncoder case class AssignCoder(coder: String) object AssignCoder { val assignCoder = AssignCoder("foo") // Encode single instance // Encode Option[AssignCoder] // Encode List[AssignCoder] This approach should work for any case class that has a corresponding CodecJson, without having to define additional implicit entity encoders. |
Beta Was this translation helpful? Give feedback.
-
In Scala 2.11.7 and http4s 0.8.6 (with argonaut),
The following code worked without issue for
AssignCoder
orOption[AssignCoder]
orList[AssignCoder]
But now in Scala 2.12.17 and http4s 0.15.16 (with argonaut),
I've to define explicitly for cases as below
Any better approach as the above is a bit tricky to add all possible combinations.
Beta Was this translation helpful? Give feedback.
All reactions