eclipse-ee4j / eclipse-ee4j/jersey

JsonBindingProvider does not use available genericType info when writing to outputstream

Open
#3,702 3 comments 0 reactions 0 assignees View on GitHub
Component: extensions Provider question
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

When trying to write a simple generic entity (Widget) to json I get the warning: Generic bound not found for type T declared in class Widget. I would expect that if I wrap the Widget in a GenericEntity> that the generic type information that is passed in to the MessageBodyWriter#writeTo method implemented in JsonBindingProvider would be passed on the the jsonb#toJson method as so: jsonb.writeTo(obj, genericType). That doesnt seem to be the case, as JsonBindingProvider ignores the generic type parameter altogether. Perhaps this is the intented behavior, but some clarification would be nice. I am also curious as to why these 2 lines were used:
`entityStream.write(jsonb.toJson(o).getBytes(AbstractMessageReaderWriterProvider.getCharset(mediaType)));
entityStream.flush();`

instead of using:
`jsonb.toJson(o, genericType, entityStream);`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.