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
zio.prelude.Newtype
Hello!
We decided to migrate from
case class RelationTypeId(x: String) extends AnyVal
to
object MyId extends zio.prelude.Newtype[String]
with a
package xxx { type RelationTypeId = RelationTypeId.type }
Now, I have to create codecs for all these datatypes by hand like
implicit val relationTypeIdCodec: JsonCodec[RelationTypeId] = new JsonCodec[RelationTypeId] { override def decodeValue(in: JsonReader, default: RelationTypeId): RelationTypeId = RelationTypeId(in.readString(RelationTypeId.unwrap(default))) override def encodeValue(x: RelationTypeId, out: JsonWriter): Unit = out.writeVal(RelationTypeId.unwrap(x)) @SuppressWarnings(Array("AsInstanceOf")) override def nullValue: RelationTypeId = null.asInstanceOf[RelationTypeId] override def decodeKey(in: JsonReader): RelationTypeId = RelationTypeId(in.readKeyAsString()) override def encodeKey(x: RelationTypeId, out: JsonWriter): Unit = out.writeVal(RelationTypeId.unwrap(x)) }
Is there a way I could teach jsoniter-scala how to create the codecs? I tried creating one like this, but can't get it to compile:
implicit def newtypeStringCodec[T <: zio.prelude.Newtype[String]]: JsonCodec[T] = new JsonCodec[T] { override def decodeValue(in: JsonReader, default: T): T = T(in.readString(T.unwrap(default))) override def encodeValue(x: T, out: JsonWriter): Unit = out.writeVal(T.unwrap(x)) @SuppressWarnings(Array("AsInstanceOf")) override def nullValue: T = null.asInstanceOf[T] override def decodeKey(in: JsonReader): T = T.apply(in.readKeyAsString()) override def encodeKey(x: T, out: JsonWriter): Unit = out.writeVal(T.unwrap(x)) } ```
The text was updated successfully, but these errors were encountered:
Hi Dominik,
Could you please share a repository or Scastie link that will reproduce your compilation errors?
Sorry, something went wrong.
No branches or pull requests
Hello!
We decided to migrate from
to
with a
Now, I have to create codecs for all these datatypes by hand like
Is there a way I could teach jsoniter-scala how to create the codecs?
I tried creating one like this, but can't get it to compile:
The text was updated successfully, but these errors were encountered: