Implicit for JsonMergePatch missing
Closed this issue · 5 comments
Hey Guys
I am trying to implement JsonMergePatch, unfortunately I am getting compile time issue
could not find implicit value for parameter P: diffson.Patch[F,Either[io.circe.ParsingFailure,io.circe.Json],scala.util.Either[io.circe.ParsingFailure,diffson.jsonmergepatch.JsonMergePatch[io.circe.Json]]]
Hi,
From what I see you are trying to have a patch on the result of parse, which returns en either, in case parsing failed. There is no such instance, as a failed parsed patch is not a patch. You need to handle error case and request the patch instance only in case parsing succeeded. This is a common thing with circe, you should have a look at their documentation.
You can also give me more code, so that I can more easily point you to where the problem occurs.
I using the exact same code as in the README.doc
val json1 = parse(source)
val json2 = parse(target)
val patch =
for {
json1 <- json1
json2 <- json2
} yield diff(json1, json2)
patch(json1) <<< compile time error
ok, I see what is confusing in the doc, I will update it.
In the meantime, the patch
call should be withing the scope of the for-comprehension.
In the doc, the snippet assumes json1
is of type Json
, which is not clearly stated.
You can try something like:
val json1 = parse(source)
val json2 = parse(target)
for {
json1 <- json1
json2 <- json2
patch = diff(json1, json2)
res <- patch(json1)
} yield res
above code still does not compile and i am using io.circe.Json
as the data type for json1
and json2
type mismatch;
found : scala.util.Try[io.circe.Json]
required: scala.util.Either[?,?]
res <- patch(json1)
It was a quick (untested) example on how the logic looks like. You need to provide the effect type annotation on patch
so that type inference can work properly.