diff options
author | Kseniya Tomskikh <ktomskih@datamonsters.co> | 2018-04-12 13:59:43 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-12 13:59:43 +0700 |
commit | 4a769764836a14ca3afa4d6a6f7f09943e290ec2 (patch) | |
tree | 113cf2991823c93b784cc4fa72d8f116b2e13be5 /src/main/scala/xyz/driver/core/rest | |
parent | 4cfa6a09c6f6692f5513ff6e31f261a020d07068 (diff) | |
download | driver-core-1.8.21.tar.gz driver-core-1.8.21.tar.bz2 driver-core-1.8.21.zip |
Fixed merge JsValues when field is absent in old value (#153)v1.8.21
Diffstat (limited to 'src/main/scala/xyz/driver/core/rest')
-rw-r--r-- | src/main/scala/xyz/driver/core/rest/PatchDirectives.scala | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/main/scala/xyz/driver/core/rest/PatchDirectives.scala b/src/main/scala/xyz/driver/core/rest/PatchDirectives.scala index 256358c..f33bf9d 100644 --- a/src/main/scala/xyz/driver/core/rest/PatchDirectives.scala +++ b/src/main/scala/xyz/driver/core/rest/PatchDirectives.scala @@ -53,10 +53,10 @@ trait PatchDirectives extends Directives with SprayJsonSupport { } protected def mergeObjects(oldObj: JsObject, newObj: JsObject, maxLevels: Option[Int] = None): JsObject = { - JsObject(oldObj.fields.map({ - case (key, oldValue) => - val newValue = newObj.fields.get(key).fold(oldValue)(mergeJsValues(oldValue, _, maxLevels.map(_ - 1))) - key -> newValue + JsObject((oldObj.fields.keys ++ newObj.fields.keys).map({ key => + val oldValue = oldObj.fields.getOrElse(key, JsNull) + val newValue = newObj.fields.get(key).fold(oldValue)(mergeJsValues(oldValue, _, maxLevels.map(_ - 1))) + key -> newValue })(collection.breakOut): _*) } |