Skip to content

Commit

Permalink
Add QueryStringRW[Boolean]
Browse files Browse the repository at this point in the history
  • Loading branch information
sake92 committed Feb 5, 2024
1 parent f855edc commit 03f6336
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions querson/src/ba/sake/querson/QueryStringRW.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ object QueryStringRW {
case other => parseError(path, s"has invalid type: ${other.tpe}")
}

given QueryStringRW[Boolean] with {
override def write(path: String, value: Boolean): QueryStringData =
QueryStringRW[String].write(path, value.toString)

override def parse(path: String, qsData: QueryStringData): Boolean =
val str = QueryStringRW[String].parse(path, qsData)
str.toBooleanOption.getOrElse(typeError(path, "Boolean", str))
}

given QueryStringRW[Int] with {
override def write(path: String, value: Int): QueryStringData =
QueryStringRW[String].write(path, value.toString)
Expand Down

0 comments on commit 03f6336

Please sign in to comment.