I was tying to convert this example for JsonPath to Scala. It should be easy with java like:
List<String> authors = JsonPath.read(json, "$.store.book[*].author");
Which I converted to this Scala:
val authors = JsonPath.read(json, "$.store.book[*].author");
Where json is a String. But I get this compile error.
ambiguous reference to overloaded definition, both method read in object JsonPath of type [T](x$1: String,
x$2: String, x$3: <repeated...>[com.jayway.jsonpath.Filter[_]])T and method read in object JsonPath of type
[T](x$1: Any, x$2: String, x$3: <repeated...>[com.jayway.jsonpath.Filter[_]])T match argument types
(String,String)
Which I assume is related to
public static <T> T read(Object json, String jsonPath, Filter... filters)
and
public static <T> T read(String json, String jsonPath, Filter... filters)
from com.jayway.jsonpath.JsonPath (version 0.9.1).
How can I disambiguate this function call?
For this specific case you could just do
This will only match one of overloaded methods (the one which takes
Object
). Presumably the method callsjson.toString
which is trivial since we already have aString
.