Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring REST, Kotin and default primitive parameters leads to an error

I get an error:

Optional long parameter 'count' is present but cannot be translated into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type

when I try to invoke this REST controller.

    @RequestMapping("/api/audio/tracks", produces = arrayOf(APPLICATION_JSON_VALUE))
    interface SomeApi {


        @RequestMapping(method = arrayOf(GET))
        fun list(@RequestParam("count", defaultValue = "10") count: Long): Any
    }

Does not spring look at defaultValue?

How to solve this kind of problem?

!Kotlin defaults do not work either

like image 541
Oleksandr Samsonov Avatar asked Sep 02 '25 16:09

Oleksandr Samsonov


1 Answers

I found solution in my situation:

The reason was because of an interface. When I placed @RequestParam("count", required = false, defaultValue = "10") in the implementation everything start working.

like image 182
Oleksandr Samsonov Avatar answered Sep 04 '25 08:09

Oleksandr Samsonov