-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Description
There seems to be inconsistencies between different JsonProvider implementations that make the concat
function work differently depending on which one is in use. Consider the following Groovy script:
@Grapes([
@Grab(group='com.google.code.gson', module='gson', version='2.13.1'),
@Grab(group='jakarta.json', module='jakarta.json-api', version='2.1.3'),
@Grab(group='org.codehaus.jettison', module='jettison', version='1.5.4'),
@Grab(group='org.json', module='json', version='20250517'),
@Grab(group='org.apache.tapestry', module='tapestry-json', version='5.9.0'),
@Grab(group='org.eclipse.parsson', module='parsson', version='1.1.7'),
@Grab(group='org.slf4j', module='slf4j-jdk14', version='2.0.11'),
@GrabConfig(systemClassLoader = true)
])
@Grab("com.jayway.jsonpath:json-path:2.9.0")
import com.jayway.jsonpath.Configuration
import com.jayway.jsonpath.JsonPath
import com.jayway.jsonpath.spi.json.JsonProvider
if(args.length != 1) {
System.err.println("Usage: concat provider")
System.exit(1)
}
String classname = args[0]
print "${classname}: "
def context = JsonPath.using(
Configuration.builder()
.jsonProvider(Class.forName("com.jayway.jsonpath.spi.json.${classname}").newInstance())
.build()
)
.parse('{"input": "foo"}')
try {
println context.read('$.concat("prefix.", $.input)')
} catch (Exception e) {
println "${e.class.canonicalName} ${e.message}"
}
When run via for classname in GsonJsonProvider JacksonJsonNodeJsonProvider JacksonJsonProvider JakartaJsonProvider JettisonProvider JsonOrgJsonProvider JsonSmartJsonProvider TapestryJsonProvider; do groovy concat.groovy $classname; done
, it produces the following output:
GsonJsonProvider: "prefix."foo
JacksonJsonNodeJsonProvider: "prefix."foo
JacksonJsonProvider: prefix.foo
JakartaJsonProvider: jakarta.json.JsonException Internal Error
JettisonProvider: java.lang.IllegalStateException org.codehaus.jettison.json.JSONException: Invalid JSON
JsonOrgJsonProvider: prefix.foo
JsonSmartJsonProvider: prefix.foo
TapestryJsonProvider: org.apache.tapestry5.json.exceptions.JSONSyntaxException A JSONObject text must start with '{' (actual: '"') at character 1 of "prefix."
To me, the behaviour where the prefix is returned without quotation marks (like how JacksonJsonProvider
, JsonOrgJsonProvider
and JsonSmartJsonProvider
work) is the most useful, and also the least surprising. Would it be possible to get the other implementations to match that?
Metadata
Metadata
Assignees
Labels
No labels