Skip to content

Commit

Permalink
use field.getUnlessDefault instead of field.get in UrlFormDataEncoder
Browse files Browse the repository at this point in the history
  • Loading branch information
bpholt committed Dec 8, 2023
1 parent 4b7a8b1 commit afb678c
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,14 @@ private[http] class UrlFormDataEncoderSchemaVisitor(
make: IndexedSeq[Any] => S
): UrlFormDataEncoder[S] = {
def fieldEncoder[A](field: Field[S, A]): UrlFormDataEncoder[S] =
compile(field.schema)
.contramap(field.get)
new UrlFormDataEncoder[S] {
private lazy val cachedEncoder = compile(field.schema)
override def encode(value: S): List[UrlForm.FormData] =
field
.getUnlessDefault(value)
.toList
.flatMap(cachedEncoder.encode)
}
.prepend(getKey(field.hints, field.label))
val encoders = fields.map(fieldEncoder(_))
struct => encoders.toList.flatMap(_.encode(struct))
Expand Down

0 comments on commit afb678c

Please sign in to comment.