eclipse-ee4j / eclipse-ee4j/jersey
EntityFilteringFeature disables jackson polymorphism
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
I'm experimenting with upgrading my ReST service from 2.25.1 to to 2.26-b09 in order to use Jersey's new EntityFilteringFeature with Jackson JSON. When I do NOT register the EntityFilteringFeature in the ResourceConfig OR when I do NOT register JacksonFeature, I get this output from my ReST resource:
```
{"innerData":{"item1":"item1","item2":"item2"},"name":"Got it!"}
```
When I DO register EntityFilteringFeature AND JacksonFeature, I get this output:
```
{"name":"Got it!","innerData":{}}
```
Note the contents of the 'innerData' field are missing when EntityFilteringFeature AND JacksonFeature are registered. I think perhaps this is because the innerData object is of type InnerDataBase - a base class with no fields, and the fields of the subclass that's actually allocated are not being rendered - only the empty base class is being rendered.
It seems like Jersey's EntityFilteringFeature is disabling or breaking proper Jackson handling of polymorphic types. Note there are no generic type issues here - only a base class and a subclass with two fields.
Note also that this works properly when EntityFilteringFeature is registered, but JacksonFeature is NOT registered - which tells me that the default Moxy json processor is working fine.
**Code:**
**Main.java:**
```
public class Main {
public static final String BASE_URI = "http://0.0.0.0:8080/myapp/";
public static HttpServer startServer() {
// create a resource config that scans for JAX-RS resources and providers
// in com.example package
final ResourceConfig rc = new ResourceConfig()
.packages("com.example")
.register(EntityFilteringFeature.class)
.register(JacksonFeature.class)
;
// create and start a new instance of grizzly http server
// exposing the Jersey application at BASE_URI
return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
}
public static void main(String[] args) throws IOException {
final HttpServer server = startServer();
System.out.println(String.format("Jersey app started with WADL available at "
+ "%sapplication.wadl\nHit enter to stop it...", BASE_URI));
System.in.read();
server.shutdown();
}
}
```
**MyResource.java:**
```
@Path("myresource")
@Produces(MediaType.APPLICATION_JSON)
public class MyResource {
public static class InnerDataBase {
}
public static class InnerData extends InnerDataBase {
public String item1 = "item1";
public String item2 = "item2";
}
public static class Data {
public String name = "Got it!";
public InnerDataBase innerData = new InnerData(); // NOTE: innerData is of base type
}
@GET
public Data getIt() {
return new Data();
}
}
```
Thanks in advance,
John
P.S. I generated the original project from the jersey-quickstart-grizzly2 maven archetype and then added dependencies from https://github.com/jersey/jersey/tree/master/examples/entity-filtering.
Contributor guide
Assessment
This issue has not been assessed yet.