Reputation: 2347
Last week, I spent a lot (too much) of hours on a strange problem. I wanted to use gnieh.diffson
to patch an existing object, the client send a PATCH /api/test/patch
request with a well formed Json patch. Then I parse the patch and apply it :
import gnieh.diffson._
val patch = JsonPatch.parse(request.body.asText.getOrElse(""))
val workspace = """{"node":{}}"""
val result = patch(workspace)
println(result)
This code works fine inside a simple App
but fails on a play Controller
:
[error] PatchException: : element node does not exist in "{\"node\":{}}" (JsonPatch.scala:140)
[error] gnieh.diffson.Operation.action(JsonPatch.scala:140)
[error] gnieh.diffson.Add.action(JsonPatch.scala:174) ...
The gnieh.diffson.JsonPatch#apply
class has 3 apply
methods :
def apply(json : scala.Predef.String, compacted : scala.Boolean = { /* compiled code */ }) : scala.Predef.String = { /* compiled code */ }
def apply(value : net.liftweb.json.JValue) : net.liftweb.json.JValue = { /* compiled code */ }
def apply[T](<value : T>)(implicit evidence\$1 : scala.Predef.Manifest[T]) : T = { /* compiled code */ }
I was thinking that the first one was called because "workspace" is a String but I was wrong. The called method was the last one, with implicit evidence..
My current solution is to parse the workspace as a net.liftweb.json.JValue
but I am not verry happy with it because :
- I can't understant why it is the last method who is called.
- I have to format the net.liftweb.json.JValue
to string to recreate a play.api.libs.json.JsObject
.. (because I need it later in my process)
Could you please explain me why the called method is the more complex one ?
Thanks a lot
Upvotes: 0
Views: 66
Reputation: 39577
There's a clause in the contract that discards alternatives that use default args:
http://www.scala-lang.org/files/archive/spec/2.11/06-expressions.html#overloading-resolution
Upvotes: 1