Skip to content

2.X.X deprecates UUIDParam, SizeParam, LocalDateParam, InstantParam, DurationParam, DateTimeParam, BooleanParam and does not give clear alternatives #3335

@mikeholler

Description

@mikeholler

I'm trying to upgrade Dropwizard from 1.3.23 to 2.0.10 and am running into some issues around the use of parameters. Specifically, I see that this commit deprecated a number of *Param classes.

Some of these, like IntParam are straightfoward. Using OptionalInt as a replacement makes sense. However, taking non-primitive parameters as an example, Optional<UUID> is NOT a sufficient replacement for UUIDParam. Using it results in me getting a 404 when using a non-UUID as input (where I previously got 400 using UUIDParam).

Additionally, and maybe this is a separate issue, I found the compatibility-preserving use of UUIDParam is strange. When diving into the source code, I found this resource method[1]:

        @GET
        @Path("/uuid")
        public String getUUID(@QueryParam("uuid") Optional<UUIDParam> uuid) {
            return uuid.orElse(new UUIDParam("d5672fa8-326b-40f6-bf71-d9dacf44bcdc")).get().toString();
        }

This construct seems an extremely clunky way to manage this. In 1.3.X, I could write code like this instead:

        @GET
        @Path("/uuid")
        public String getUUID(@Nullable @QueryParam("uuid") UUIDParam uuid) {
            if (uuid != null) {
                return uuid.get()
            } else {
                return "d5672fa8-326b-40f6-bf71-d9dacf44bcdc"
            }
        }

You can see in the above that there is a lot of unnecessary conversion going on (we construct a UUID via UUIDParam and validate it, even though we just want to return a String). I use Kotlin primarily, my preferred example above would be even simpler:

uuid.get()?.toString ?: "d5672fa8-326b-40f6-bf71-d9dacf44bcdc"

What I'd prefer overall is something that worked like this:

        @GET
        @Path("/uuid")
        public String getUUID(@Nullable @QueryParam("uuid") Optional<UUID> uuid) {
            return uuid.map { it.toString() }.orElse("d5672fa8-326b-40f6-bf71-d9dacf44bcdc")
        }

More than anything, really, I just want some guidance for the right way to handle various param types, especially in light of the deprecation. The documentation is light on this (I found the MR saying AbstractParam and child classes will be removed, but nothing saying why, and no code showing what would replace the more complicated use-cases like UUIDParam above). I would love to see this improved. Until then, I'm hesitant to upgrade to 2.X.X. Param handling is still confusing in 1.X.X, but at least I won't have to worry about behavior changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleStale issue or pull request which will be closed soon

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions