UUID Is not deserialized in Resource Param

803 views
Skip to first unread message

homerlex

unread,
Oct 6, 2015, 1:45:07 PM10/6/15
to dropwizard-dev

I have a resource that takes a UUID as a HeaderParam 


@POST
@Path("/inquiry")
@UnitOfWork
@Consumes(MediaType.APPLICATION_JSON)
public Response inquiry(@HeaderParam("someGUID") UUID someGUID) {
    System.out.println("*** Here ***");
    return Response.ok().build();

When I hit the end point with a valid UUID in the header I get an error like this:

0289-4a42-a757-80cc6e4eb0a5, origin_ip=127.0.0.1] - Error processing request. {"status":400,"code":10000,"message":"HTTP 400 Bad Request","link":null,"developerMessage":null,"errors":[]}
! com.fasterxml.jackson.core.JsonParseException: Unexpected character ('c' (code 99)): Expected space separating root-level values
!  at [Source: 0c006839-404e-4273-990a-4a69d77d5b70; line: 1, column: 3]

If I take the Param in as a String I can convert it (in the method) to a UUID just fine with:
@POST
@Path("/inquiry")
@UnitOfWork
@Consumes(MediaType.APPLICATION_JSON)
public Response inquiry(@HeaderParam("someGUID") String someGUID) {
    System.out.println(UUID.fromString(someGUID));
    return Response.ok().build();

Any idea why it doesn't work as a UUID in the params?

Ryan Kennedy

unread,
Oct 6, 2015, 1:55:45 PM10/6/15
to dropwiz...@googlegroups.com
Can you provide the raw JSON being passed? I have it working (although with query/form parameters, as opposed to a header parameter) in an 0.8.x application. Also, which UUID is that referring to? Is it a java.util.UUID? JAX-RS should magically work with java.util.UUID because it has a static `UUID fromString(String)` method. If you’re using a different UUID implementation that doesn’t have a fromString method or a constructor that takes a single String argument, that would explain why it’s not working for you.

Ryan
> --
> You received this message because you are subscribed to the Google Groups "dropwizard-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-de...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Ryan Kennedy

unread,
Oct 6, 2015, 2:09:55 PM10/6/15
to dropwiz...@googlegroups.com
Also, just noticing this was sent to dropwizard-dev. This topic is probably more appropriate for dropwizard-users.

Ryan

homerlex

unread,
Oct 6, 2015, 3:21:36 PM10/6/15
to dropwizard-dev
I get the same error when using a @QueryParam.  I am referring to java.util.UUID as well.  Also on dropwizard 0.8.

I just confirmed that it does, however, work in the Hello World example.  Must be something in my application getting in the way.


homerlex

unread,
Oct 6, 2015, 3:21:55 PM10/6/15
to dropwizard-dev
oops - sorry about that

Ryan Kennedy

unread,
Oct 7, 2015, 12:54:15 AM10/7/15
to dropwiz...@googlegroups.com
Looking more closely at the error you’re seeing, I think you’re sending invalid JSON to the endpoint. Why are you using the @Consumes annotation for a method that doesn’t take any parameters for the body of the request? Can you share the raw HTTP request that triggers the response you’re seeing?

I implemented a quick proof of concept for handling UUIDs in both header and path parameters and it works fine locally on 0.8.4 for me.

https://gist.github.com/ryankennedy/c18354ea6da0f9de803e

Ryan


> On Oct 6, 2015, at 10:45 AM, homerlex <home...@gmail.com> wrote:
>
>

homerlex

unread,
Oct 7, 2015, 7:04:26 AM10/7/15
to dropwizard-dev
Thanks for the sample. As I mentioned above I can get it to work in the hello world example (slightly modified of course) using the same payload.  So it must be something about the way my application (which has a lot going on) is configured.  I'm trying to narrow it down.

As far as having the @Consumes there - it was just left over from when I was trying different things.

homerlex

unread,
Oct 7, 2015, 12:53:19 PM10/7/15
to dropwizard-dev
I figured out what was getting in the way.  The Application class that my class extended was  registering 

JacksonJsonParamConverterProvider.  If I take that out all is well.  Just need to find out why that was added.


Thanks again for the help.

Harsh Shah

unread,
Sep 5, 2017, 3:50:08 PM9/5/17
to dropwizard-dev
@homerlex How exactly are you removing the JacksonJsonParamConverterProvider? I am facing a similar issue parsing UUID from a JSON. Gives errors like
--> Unexpected character, expected space separating root-level values
--> Unrecognized token, was expecting ('true' .... )
such errors on different JSON.
Reply all
Reply to author
Forward
0 new messages