Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-2107

Unable to use Bean Validation with JSON-B

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Critical
    • 4.0.0.Beta7
    • 3.6.2.Final
    • None
    • None

    Description

      When trying to use the JSON-B provider (aka json-binding) with a BV related example, I discovered it does not play well with the Bean Validation support:

      Caused by: org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type: org.jboss.resteasy.api.validation.ViolationReport of media type: application/json
      at org.jboss.resteasy.core.ServerResponseWriter.lambda$writeNomapResponse$2(ServerResponseWriter.java:105)
      at org.jboss.resteasy.core.interception.jaxrs.ContainerResponseContextImpl.filter(ContainerResponseContextImpl.java:405)
      at org.jboss.resteasy.core.ServerResponseWriter.executeFilters(ServerResponseWriter.java:218)

      The issue here is that ViolationReport has some JAXB annotations (as we also need it to work with XML) and, in this case, the JSON-B provider is not considered as valid:
      https://github.com/resteasy/Resteasy/blob/3.6/providers/json-binding/src/main/java/org/jboss/resteasy/plugins/providers/jsonb/JsonBindingProvider.java#L68

      I don't think these JAXB conditions is a good idea for 2 reasons:

      • having JAXB annotations don't say you won't use JSON to serialize the object;
      • JAXB is gone in stock JDK 11 and the JsonBindingProvider won't work if JAXB is not in the classpath. So you would need to add a JAXB API jar to your classpath to have JSON-B working, which sounds like a bad idea.

      I think we should get rid of these JAXB conditions (and of the condition on the presence of JSON-B annotations as they are not required and it won't make sense anymore).

      Attachments

        Issue Links

          Activity

            People

              rhn-engineering-ema Jim Ma
              gsmet@redhat.com Guillaume Smet
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: