Skip to content

Commit

Permalink
Improve behavior of JsonOptic.set (fixes #13)
Browse files Browse the repository at this point in the history
  • Loading branch information
danslapman committed Mar 23, 2023
1 parent f56df78 commit a8c355e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ package object optics {
}
}
.getOrElse(construct(part, mod(None)))
case Traverse => json => json.withArray(arr => Json.fromValues(arr.map(j => mod(Some(j)))))
case Traverse =>
json =>
json.asArray.map(arr => Json.fromValues(arr.map(j => mod(Some(j))))).getOrElse(construct(part, mod(None)))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ class OpticSpec extends RefSpec with Matchers {

result shouldBe json"""{"a": [{"b": 4}, {"b": 4}, {"b": 4}]}"""
}

def `should properly re-create complete structure`: Assertion = {
val target = Json.obj()
val result = optic.set(Json.fromInt(4))(target)

result shouldBe json"""{"a": [{"b": 4}]}"""
}
}

object `json getter` {
Expand Down
2 changes: 1 addition & 1 deletion backend/project/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object Settings {

val common = Seq(
organization := "ru.tinkoff",
version := "3.7.0",
version := "3.7.1",
scalaVersion := "2.13.10",
Compile / packageDoc / publishArtifact := false,
Compile / packageSrc / publishArtifact := false,
Expand Down

0 comments on commit a8c355e

Please sign in to comment.