Skip to content

Wrapped Option type results in Json decoding failure missing required field #176

@kamilkloch

Description

@kamilkloch

(Scala 2)

type WsTag = WsTag.Type

object WsTag extends NewtypeWrapped[Option[Long]] with DerivedCirceCodec

case class A(wsTag: WsTag, i: Int)

implicit val decoder: Decoder[A] = io.circe.generic.semiauto.deriveDecoder
println(io.circe.parser.parse("""{"i" : 1}""").value.as[A])

results in

Left(DecodingFailure at .wsTag: Missing required field)

Replacing WsTag with the underlying type Option[Long] in A gets rid of the error:

case class A(wsTag: Option[Long], i: Int)

println(io.circe.parser.parse("""{"i" : 1}""").value.as[A])

> Right(A(None,1))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions