Hi Vlad, JSON binding providers (like Jackson, JSON-B implementations, etc.) are not required by the JAX-RS specification. Section 4.2.4 of the spec lists the provider media types that must be supported by a compliant JAX-RS implementation - and most (if not all) of them are types that are built-in to the JDK - XML, plain text, etc.
Some vendors that package CXF (WebSphere Liberty, for sure - and possibly TomEE and others) will also package built-in providers that will handle JSON binding without additional config or libraries. But if you are using CXF outside of these vendors, then you will need to package and register your own provider for JSON (Jackson is probably the best for EE7, but if you are looking at Java EE8 you may want to consider JSON-B). As for choosing the response, that must be specified by the client in the Accept header. If this header is left empty, then the implementation (CXF) is free to choose any of the media types from the @Produces annotation. My guess is that it will choose the first media type listed in the annotation, but if you want your app to be portable, you should not rely on that behavior. If you only want to respond back with JSON, then I would suggest removing the "application/xml" media type from the @Produces annotation. If you want to support both JSON and XML, but always use JSON when the client has not specified an Accept header, then I would suggest adding a ContainerRequestFilter to the application that will check for the existence of the Accept header, and add "Accept: application/json" if the header does not already exist. Hope this helps, Andy On Thu, Jun 21, 2018 at 9:14 AM vlad.balan <vlad.ba...@gmail.com> wrote: > Hello > > thanks whoever reads this post. > > I understodd from the JEE 7 tutorial that whenever you use JAXB classes as > parameters or return types > you can also use the them for generating/reading JSON. > > It's enough to add "application/json" : > > @Produces({"application/xml","application/json"}) or > @Consumes({"application/xml","application/json"}) > > > But i tried this in CXF JAX-RS and it didn't work without adding the > Jackson > JSON provider. > > > > I cite the tutorial: > > The JEE tutorial says in chapter 31.7.3 > > " > JAX-RS can automatically read and write XML using JAXB, but it can also > work > with > JSON data > > > ..... > > > You can add the format application/json or MediaType.APPLICATION_JSON to > the > @Produces annotation in resource methods to produce responses with JSON > data: > > > @GET > @Path("/get") > @Produces({"application/xml","application/json"}) > public Product getProduct() { ... } > > > In this example, the default response is XML, but the response is a JSON > object if the > client makes a GET request that includes this header: > Accept: application/json > > > " > > > Thanks. > > > > > > -- > Sent from: http://cxf.547215.n5.nabble.com/cxf-user-f547216.html >