-
Notifications
You must be signed in to change notification settings - Fork 6
Description
ClassPath:
com.revinate:assertj-json:1.0.1
com.jayway.jsonpath:json-path:2.0.0
com.google.code.gson:gson:2.7
Code to reproduce:
String json = "{"id":186,"areaIds":[39]}";
Configuration config = Configuration.builder()
.jsonProvider(new GsonJsonProvider())
.mappingProvider(new GsonMappingProvider())
.build();
DocumentContext response = JsonPath.using(config).parse(content);
JsonPathAssert.assertThat(response)
.jsonPathAsListOf("$.areaIds", Integer.class)
.containsExactly(39);
java.lang.AssertionError:
Expecting:
<[39.0]>
to contain exactly (and in same order):
<[39]>
but some elements were not found:
<[39]>
and others were not expected:
<[39.0]>
After a quick investigation:
com.jayway.jsonpath.spi.mapper.GsonMappingProvider
@OverRide
public T map(Object source, TypeRef targetType, Configuration configuration) { // source "[47]"
try {
return (T) factory.call().getAdapter(TypeToken.get(targetType.getType())).fromJsonTree((JsonElement) source); // result "[47.0]"
} catch (Exception e){
throw new MappingException(e);
}
}
com.google.gson.internal.bind,ObjectTypeAdapter
JsonToken token is a NUMBER and ObjectTypeAdapter will always return Double.
case NUMBER: // * A JSON number represented in this API by a Java {@code double}, {@code long}, or {@code int}.
return in.nextDouble();