jsonapi-converter
jsonapi-converter copied to clipboard
UnrecognizedPropertyException when reading an errors response.
Response I'm using to test:
{"jsonapi":{"version":"1.0"},"errors":[{"status":404,"title":"An error"}]}
When reading this response with a ResourceConverter, an exception is generated:
java.lang.RuntimeException: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "jsonapi" (class com.github.jasminb.jsonapi.models.errors.Errors), not marked as ignorable (one known property: "errors"])
at [Source: N/A; line: -1, column: -1] (through reference chain: com.github.jasminb.jsonapi.models.errors.Errors["jsonapi"])
at com.github.jasminb.jsonapi.ValidationUtils.ensureNotError(ValidationUtils.java:51)
at com.github.jasminb.jsonapi.ResourceConverter.readDocument(ResourceConverter.java:190)
at com.github.jasminb.jsonapi.ResourceConverter.readDocument(ResourceConverter.java:173)
at it.nicolaisotta.testclient.Main.main(Main.java:24)
Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "jsonapi" (class com.github.jasminb.jsonapi.models.errors.Errors), not marked as ignorable (one known property: "errors"])
at [Source: N/A; line: -1, column: -1] (through reference chain: com.github.jasminb.jsonapi.models.errors.Errors["jsonapi"])
at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:62)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:834)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1094)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1470)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1448)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:282)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:140)
at com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:3770)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2099)
at com.fasterxml.jackson.databind.ObjectMapper.treeToValue(ObjectMapper.java:2596)
at com.github.jasminb.jsonapi.ErrorUtils.parseError(ErrorUtils.java:45)
at com.github.jasminb.jsonapi.ValidationUtils.ensureNotError(ValidationUtils.java:49)
... 3 more
You should be able to instantiate converter instance using configured object mapper which will ignore unknown properties if needed.
Yes, configuring an ObjectMapper avoids the exception.
I would handle the jsonapi
object natively in the lib since it's is in the specification, but that's just my 2 cents.
I just use ErrorUtils.parseErrorResponse
, but it seems that function fails somehow: at com.github.jasminb.jsonapi.ErrorUtils.parseErrorResponse(ErrorUtils.java:33)
. I don't think this error should be responsibility of the user.
@ben221199 you are right, I will publish a release that adds support for JSON API doc object
as part of both error and regular resource response.
Fixed in #263