2

I am using the @JsonTypeInfo mechanism in order to achieve Polymorphism of data objects sent to a REST API. I've encountered the problem of my type property added twice, which is clearly explained is this jackson issue (I'm not putting my code in here because the code in the top of that issue is similar to mine). According to this issue, it's a known problem which can only be solved by using the JsonTypeInfo.As.EXISTING_PROPERTY.

Unfortunately, I didn't find any code example showing a simple use case using the JsonTypeInfo.As.EXISTING_PROPERTY - I mean, I thought these Unit tests, which are part of the jackson-databind project, can be used as an example, but the moment I'm replacing JsonTypeInfo.As.PROPERTY with JsonTypeInfo.As.EXISTING_PROPERTY, I'm getting response with status code 400 from my server, with the following response body:

"Do not know how to construct standard type serializer for inclusion type: EXISTING_PROPERTY".

I've debugged it, and all my business logic works fine - until the point where the response object is sent back to client (I'm using the standard javax.ws.rs.core.Response.ResponseBuilder to build the response with all the retrieved data objects)

I've tried using another solution described in: Unexpected duplicate key error using @JsonTypeInfo property , which suppose to solve the duplicate key issue and still use the JsonTypeInfo.As.PROPERTY - but it just didn't solve the duplication issue.

My server is tomcat 8, my code on the server-side is written in Java 8, I'm using Spring 4, Jersey 2.14 for REST, and I've configured my project to work with the latest jackson-annotations version from their git repository (2.6.0-rc3-SNAPSHOT) - since in the jackson ticket they've specified that only from this version JsonTypeInfo.As.EXISTING_PROPERTY will be working properly.

Community
  • 1
  • 1
shemlar
  • 21
  • 2

1 Answers1

0

One way to debug this would be to first see if you can make deserialization work in unit test; similar to one you see, using 2.6.0-rc3-SNAPSHOT, but your own types.

Assuming that works (as expected as per bug fix), question would be what in JAX-RS stack causes the issue. There are couple of possibilities:

  1. Version of Jackson that is included is not 2.6.0-rc3-SNAPSHOT. Maven transitive dependencies are tricky, so you may need to see mvn tree:dependency to see if you are getting older version of jackson-databind
  2. Jackson JAX-RS provider has an issue. I am not aware of issues that would directly affect this case, but if your root value is the polymorphic type, that could be the reason.

If you can see which part (core databind or JAX-RS) causes the problem, I would recommend you file a new github issue in respective project (jackson-databind or jackson-jaxrs-providers).

StaxMan
  • 113,358
  • 34
  • 211
  • 239