Choose the annotation to add on line 4 to enable the client to receive a JSON representation of the instance of Value that is returned (Choose one):

Given the class:

Choose the annotation to add on line 4 to enable the client to receive a JSON representation of the instance of Value that is returned (Choose one):

Given the class:

Choose the annotation to add on line 4 to enable the client to receive a JSON representation of the instance of Value that is returned (Choose one):

A.
@Produces(“application/json”);

B.
@Consumes(“application/json”);

C.
No annotation is needed, since JAX-RS supports marshalling and unmarshalling of JSON records.

D.
No annotation is possible, since JAX-RS does not support marshalling and unmarshalling of JSON records.



Leave a Reply 6

Your email address will not be published. Required fields are marked *


Marquek

Marquek

It’s D?

Leo Yu

Leo Yu

jax-ws doesn’t support marshal of JSON? the source?

Gp

Gp

the answer A is correct

Mohamed Fayek Saber

Mohamed Fayek Saber

The @Produces annotation is used to specify the MIME media types of representations a resource can produce and send back to the client.

The @Consumes annotation is used to specify the MIME media types of representations that can be consumed by a resource.

so he wants to enable the client to receive A Json So it should not be A

i think it is D

Mohamed Fayek Saber

Mohamed Fayek Saber

Sorry A is correct , i Test the same example in NetBeans IDE JDK 1.7 it is working need only @Produces(MediaType.APPLICATION_JSON)

why it working because :

Marshalling is the nothing but the process of converting in-memory object into persisting or transportable format.

Now a days most of the web services are returning the response as JSON object. Some people are still using XML as their preferred transport medium.

JAX-RS api has introduced a generic and pluggable interface called MessageBodyWriter for doing the marshalling.

http://h2labz.blogspot.ae/2014/12/marshalling-java-to-json-in-jax-rs.html

public interface MessageBodyWriter
Contract for a provider that supports the conversion of a Java type to a stream. A MessageBodyWriter implementation may be annotated with Produces to restrict the media types for which it will be considered suitable.

Providers implementing MessageBodyWriter contract must be either programmatically registered in a JAX-RS runtime or must be annotated with @Provider annotation to be automatically discovered by the JAX-RS runtime during a provider scanning phase.

Andrei

Andrei

A) is correct

@Produces refers to the type that the method returns.
@Consumes refers to the body that the JAX-RS service consumes.

C) is only valid if you have the JSON jackson library added to the dependencies.