val document = gsonJsonProvider.parse(text.toString)
paths.map { path: String =>
JsonPath.read(document, path).toString
}.asJava
This didn't work, as I would get exceptions:
com.jayway.jsonpath.PathNotFoundException: Expected to find an object with property ['requestId'] in path $ but found 'com.google.gson.JsonObject'. This is not a json object according to the JsonProvider: 'com.jayway.jsonpath.spi.json.JsonSmartJsonProvider'.
at com.jayway.jsonpath.internal.path.PropertyPathToken.evaluate(PropertyPathToken.java:69)
If I override all of the mappings:
Configuration.setDefaults(new Configuration.Defaults() {
private val json: JsonProvider = new GsonJsonProvider()
private val mapping: MappingProvider = new GsonMappingProvider()
override def jsonProvider(): JsonProvider = json
override def mappingProvider(): MappingProvider = mapping
override def options(): java.util.Set[Option] = Set.empty[Option].asJava
})
Then the above code does work, but it adds some additional boiler plate I'm not super excited about.
I literally have 3 lines of code referencing jsonpath:
private val gsonJsonProvider: GsonJsonProvider = new GsonJsonProvider()
val document = gsonJsonProvider.parse(text.toString)
JsonPath.read(document, path).toString
The first two are explicit for the GsonJsonProvider, is there a similar way I can be explicit for the JsonPath.read()?
I've tried looking into singleton but nothing is popping out at me (https://github.com/jayway/JsonPath/blob/master/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java#L595)
What's the "lightest touch" for setting up if I always am going to use GsonJsonProvider?