bynk.json.nested_option_plain
Error A plain-JSON route's response type, or the argument of Json.encodePlain, contains an Option[U] whose payload U can itself encode as null (Option[T] or ()), so Some(U) and None would both be written null.
Plain JSON writes Some(v) as v and None as null, so it can only be read back if v is never itself null. In an Option[Option[T]] or an Option[()], Some(None) and None (or Some(()) and None) would both be written null, and the decoder could not tell them apart. The compiler refuses the type wherever plain encoding is asked for: in the response type of a route whose json { options: plain } or @json(options: plain) applies, or in the argument of Json.encodePlain, through records, sums, containers and generic arguments alike. The tagged form, which Json.encode and a route's default use, writes Option as {"kind":"Some","value":…} and has no such ambiguity. Either flatten the type, model the distinction as a sum type, or keep that route tagged.
Example
type Row = { id: String, note: Option[Option[String]] }
on GET("/rows") () -> Effect[HttpResult[List[Row]]] by v: Visitor { … } // ✗ `Some(None)` and `None` both write `null`
type Row = { id: String, note: Option[String] } // ✓In the Book
See also
- Every code in its category, Other, on the diagnostic index.
bynk explain bynk.json.nested_option_plainshows the same from the installed toolchain, without a network.