You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by eanbiso <bi...@hotmail.it> on 2013/07/05 13:20:14 UTC
JacksonJaxbJsonProvider anomalous behavior (add unexpeted chars to
the String returned by web method)
Hi all,
I've published a rest endPoint adding the JacksonJaxbJsonProvider at
publication time (I've added it to properly support swagger).
All is good but some times the JacksonJaxbJsonProvider seems to smudge the
response adding unexpected chars.
For example, I have an endPoint with this web method:
@GET
@Path("/getWSLatency/{appGardenID}/{lowerTimestamp}/{upperTimestamp}")
@Produces("application/json")
@ApiOperation(value = "Retrieves the latency of API invocation by the given
app garden.",
notes = "Refers to KPI: 3.17.9 WS Latency: Latency of WS invocation.",
response = String.class)
public String getWSLatency(
@ApiParam(value = "appGardenID", required = true)
@PathParam("appGardenID") int appGardenID,
@ApiParam(value = "lowerTimestamp", required = true)
@PathParam("lowerTimestamp") long lowerTimestamp,
@ApiParam(value = "upperTimestamp", required = true)
@PathParam("upperTimestamp") long upperTimestamp,
@ApiParam(value = "apiName", required = false, defaultValue="")
@DefaultValue("") @QueryParam("apiName") String apiName,
@ApiParam(value = "serviceProvider", required = false,
defaultValue="65535") @DefaultValue("65535") @QueryParam("serviceProvider")
long serviceProvider,
@ApiParam(value = "userName", required = false, defaultValue="")
@DefaultValue("") @QueryParam("userName") String userName);
returning a String like this:
[{"latencyMax":48,"latencyMin":48,"latencySum":48,"msgNumber":1,"timestamp":1373018880000},{"latencyMax":53,"latencyMin":26,"latencySum":621,"msgNumber":16,"timestamp":1373018910000}]
Adding the JacksonJaxbJsonProvider to the providers list the String arrives
client side so formatted:
"[{\"latencyMax\":46,\"latencyMin\":33,\"latencySum\":324,\"msgNumber\":8,\"timestamp\":1373019420000},{\"latencyMax\":58,\"latencyMin\":32,\"latencySum\":639,\"msgNumber\":16,\"timestamp\":1373019450000}]"
while if I remove it the String arrives client side as expected.
It seems that the provider has modified the String adding the initial and
ending " and adding \ before ".
How can I continue to use the JacksonJaxbJsonProvider (required by swagger)
without anomalous behavior?
Best regards,
Andrea
--
View this message in context: http://cxf.547215.n5.nabble.com/JacksonJaxbJsonProvider-anomalous-behavior-add-unexpeted-chars-to-the-String-returned-by-web-method-tp5730332.html
Sent from the cxf-user mailing list archive at Nabble.com.
RE: JacksonJaxbJsonProvider anomalous behavior (add unexpeted chars
to the String returned by web method)
Posted by eanbiso <bi...@hotmail.it>.
Hi Sergey,
the problem was that my web method returned a single String already json formatted and corresponding to more json elements...
Using the JacksonJaxbJsonProvider it was modified adding a new json formatting that added the unexpected chars.
So I solved it using a provider that extends the JacksonJaxbJsonProvider and skipping its writeTo method for the String:
@Provider
@Produces(MediaType.APPLICATION_JSON)
public class JacksonJsonProvider extends JacksonJaxbJsonProvider {
public JacksonJsonProvider() {
super();
}
@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType)
{
if (genericType.equals(String.class)){
return false;
}else{
return super.isWriteable(type, genericType, annotations, mediaType);
}
}
}
In this way the original String produced by the web method is returned to the client without any change.
Best regards,
Andrea
Date: Fri, 5 Jul 2013 06:06:51 -0700
From: ml-node+s547215n5730341h91@n5.nabble.com
To: bisomagic@hotmail.it
Subject: Re: JacksonJaxbJsonProvider anomalous behavior (add unexpeted chars to the String returned by web method)
Hi
On 05/07/13 13:20, eanbiso wrote:
> Hi all,
> I've published a rest endPoint adding the JacksonJaxbJsonProvider at
> publication time (I've added it to properly support swagger).
> All is good but some times the JacksonJaxbJsonProvider seems to smudge the
> response adding unexpected chars.
> For example, I have an endPoint with this web method:
>
> @GET
> @Path("/getWSLatency/{appGardenID}/{lowerTimestamp}/{upperTimestamp}")
> @Produces("application/json")
> @ApiOperation(value = "Retrieves the latency of API invocation by the given
> app garden.",
> notes = "Refers to KPI: 3.17.9 WS Latency: Latency of WS invocation.",
> response = String.class)
> public String getWSLatency(
> @ApiParam(value = "appGardenID", required = true)
> @PathParam("appGardenID") int appGardenID,
> @ApiParam(value = "lowerTimestamp", required = true)
> @PathParam("lowerTimestamp") long lowerTimestamp,
> @ApiParam(value = "upperTimestamp", required = true)
> @PathParam("upperTimestamp") long upperTimestamp,
> @ApiParam(value = "apiName", required = false, defaultValue="")
> @DefaultValue("") @QueryParam("apiName") String apiName,
> @ApiParam(value = "serviceProvider", required = false,
> defaultValue="65535") @DefaultValue("65535") @QueryParam("serviceProvider")
> long serviceProvider,
> @ApiParam(value = "userName", required = false, defaultValue="")
> @DefaultValue("") @QueryParam("userName") String userName);
>
> returning a String like this:
>
> [{"latencyMax":48,"latencyMin":48,"latencySum":48,"msgNumber":1,"timestamp":1373018880000},{"latencyMax":53,"latencyMin":26,"latencySum":621,"msgNumber":16,"timestamp":1373018910000}]
>
this is a correct sequence, I wonder, which provider produces this
sequence ? CXF JSONProvider is not supporting String[]
> Adding the JacksonJaxbJsonProvider to the providers list the String arrives
> client side so formatted:
>
>
> "[{\"latencyMax\":46,\"latencyMin\":33,\"latencySum\":324,\"msgNumber\":8,\"timestamp\":1373019420000},{\"latencyMax\":58,\"latencyMin\":32,\"latencySum\":639,\"msgNumber\":16,\"timestamp\":1373019450000}]"
>
> while if I remove it the String arrives client side as expected.
>
> It seems that the provider has modified the String adding the initial and
> ending " and adding \ before ".
> How can I continue to use the JacksonJaxbJsonProvider (required by swagger)
> without anomalous behavior?
Hmm, I'd expect Jackson provider to do it correctly, please ask at
Jackson forums
Cheers, Sergey
> Best regards,
> Andrea
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/JacksonJaxbJsonProvider-anomalous-behavior-add-unexpeted-chars-to-the-String-returned-by-web-method-tp5730332.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com
If you reply to this email, your message will be added to the discussion below:
http://cxf.547215.n5.nabble.com/JacksonJaxbJsonProvider-anomalous-behavior-add-unexpeted-chars-to-the-String-returned-by-web-method-tp5730332p5730341.html
To unsubscribe from JacksonJaxbJsonProvider anomalous behavior (add unexpeted chars to the String returned by web method), click here.
NAML
--
View this message in context: http://cxf.547215.n5.nabble.com/JacksonJaxbJsonProvider-anomalous-behavior-add-unexpeted-chars-to-the-String-returned-by-web-method-tp5730332p5730396.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: JacksonJaxbJsonProvider anomalous behavior (add unexpeted chars
to the String returned by web method)
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 05/07/13 13:20, eanbiso wrote:
> Hi all,
> I've published a rest endPoint adding the JacksonJaxbJsonProvider at
> publication time (I've added it to properly support swagger).
> All is good but some times the JacksonJaxbJsonProvider seems to smudge the
> response adding unexpected chars.
> For example, I have an endPoint with this web method:
>
> @GET
> @Path("/getWSLatency/{appGardenID}/{lowerTimestamp}/{upperTimestamp}")
> @Produces("application/json")
> @ApiOperation(value = "Retrieves the latency of API invocation by the given
> app garden.",
> notes = "Refers to KPI: 3.17.9 WS Latency: Latency of WS invocation.",
> response = String.class)
> public String getWSLatency(
> @ApiParam(value = "appGardenID", required = true)
> @PathParam("appGardenID") int appGardenID,
> @ApiParam(value = "lowerTimestamp", required = true)
> @PathParam("lowerTimestamp") long lowerTimestamp,
> @ApiParam(value = "upperTimestamp", required = true)
> @PathParam("upperTimestamp") long upperTimestamp,
> @ApiParam(value = "apiName", required = false, defaultValue="")
> @DefaultValue("") @QueryParam("apiName") String apiName,
> @ApiParam(value = "serviceProvider", required = false,
> defaultValue="65535") @DefaultValue("65535") @QueryParam("serviceProvider")
> long serviceProvider,
> @ApiParam(value = "userName", required = false, defaultValue="")
> @DefaultValue("") @QueryParam("userName") String userName);
>
> returning a String like this:
>
> [{"latencyMax":48,"latencyMin":48,"latencySum":48,"msgNumber":1,"timestamp":1373018880000},{"latencyMax":53,"latencyMin":26,"latencySum":621,"msgNumber":16,"timestamp":1373018910000}]
>
this is a correct sequence, I wonder, which provider produces this
sequence ? CXF JSONProvider is not supporting String[]
> Adding the JacksonJaxbJsonProvider to the providers list the String arrives
> client side so formatted:
>
>
> "[{\"latencyMax\":46,\"latencyMin\":33,\"latencySum\":324,\"msgNumber\":8,\"timestamp\":1373019420000},{\"latencyMax\":58,\"latencyMin\":32,\"latencySum\":639,\"msgNumber\":16,\"timestamp\":1373019450000}]"
>
> while if I remove it the String arrives client side as expected.
>
> It seems that the provider has modified the String adding the initial and
> ending " and adding \ before ".
> How can I continue to use the JacksonJaxbJsonProvider (required by swagger)
> without anomalous behavior?
Hmm, I'd expect Jackson provider to do it correctly, please ask at
Jackson forums
Cheers, Sergey
> Best regards,
> Andrea
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/JacksonJaxbJsonProvider-anomalous-behavior-add-unexpeted-chars-to-the-String-returned-by-web-method-tp5730332.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com