'can we have a default parameter in java akka http?

like below code

                 post(() -> route(
                    pathPrefix("scheduleStatus", () ->
                            path("send", () ->
                                    parameter("type", type ->
                                            entity(Jackson.unmarshaller(Car.class), car -> {
                                                return complete(car.getColor());
                                            })
                                    )

                            )
                    ))

can we have default value for type? like we think default car type is bmw etc? how can we achieve this in java akka http?



Solution 1:[1]

Akkording to the documentation you cannot do it with parameter() - you need to use parameterOptional():

    post(() -> route(
        pathPrefix("scheduleStatus", () ->
            path("send", () ->
                parameterOptional("type", type ->
                    entity(Jackson.unmarshaller(Car.class), car -> {
                        return complete(car.getColor());
                    })
                )
            )
        )
    )

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Thomas Kläger