Em Ae
Em Ae

Reputation: 8704

What is more efficient

I have a schema, which will result in an XML like this

<root-element>
   <element_1>value_a<element_1>
   <element_2>value_b<element_2>
   <element_3>value_c<element_3>
   <element_1>value_a<element_1>
   <element_2>value_b<element_2>
   <element_3>value_c<element_3>
</root-element>

Now, in my REST Method, there are two different methods which receives input call

@POST
@Path(PATH+"/{" + PATH_2 + "}/query-by-list." + XML)
@Consumes (MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_XML)
public Response getShipmentListXML (String xmlRequest) 

and other we can do is like

@POST
@Path(PATH+"/{" + PATH_2 + "}/query-by-list." + XML)
@Consumes (MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_XML)
public Response getShipmentListXML (JAXBElement<ShipmentListType> jaxbShipmentListType) 

in short, the first method is getting the "raw" request and the second one is marshalling the request into appropriate jaxb element type.

Question is, which one would be faster ? The one which is taking raw request or the one which is marshalling ... or ... would that making any request ?

P.S: The raw request is marshalling the input raw string into jaxbobject anyways. the only difference is that the input request (xml body) is used somewhere else too. which can be converted from those jaxb object.

Upvotes: 0

Views: 52

Answers (1)

TheArchitect
TheArchitect

Reputation: 2173

If you don't need to read or store the XML payload, then it shouldn't make any difference from a performance standpoint whether you do the unmarshalling manually or via Jersey, but the latter will make for less code and work.

If you do need to read or store the XML payload, then letting Jersey do the unmarshalling for you is less efficient as it will require you to remarshall it later on. In this case, you might as well just get the raw String.

Upvotes: 1

Related Questions