hikaku icon indicating copy to clipboard operation
hikaku copied to clipboard

Query Parameter based on an object

Open cc-jhr opened this issue 6 years ago • 2 comments

Is your feature request related to one or multiple existing converters? SpringConverter

Describe the solution you'd like Spring allows query parameter definitions by simply passing an object.

On extracting query parameters every controller method should be check for parameters (objects, not interfaces) without any spring annotation. The limitation to the usual spring controller method annotations is important, because the parameter could have a JSR-303 annotation or the like.

Easiest way to to get on all properties without having to do the reflection manually might be to serialize the type as json and and then extract the paths from the json. Suggestion for seriallization lib could be klaxon or moshi

Unchecked:

  • How do primitives such as String, Int, Long etc behave?

Additional context Simple objects

data class Params1 (
  var a: String
  var b: String
)

data class Params2 (
  var a: String
  var c: String
)

@GetMapping("/todos")
fun getAllTodos(params1: Params1, params2 Params2) {
  /*
    calling: /todos?a=val1&b=val2&c=val3

    will result in :
    Params1(a = val1, b = val2)
    Params2(a = val1, c = val3)

  */
}

Nested object

data class Params1 (
  var a: String
  var b: Params2
)

data class Params2 (
  var a: String
  var c: String
)

@GetMapping("/todos")
fun getAllTodos(params1: Params1) {
  /*
    calling: /todos?a=val1&b.c=nestedvalue&c=othervalue

    will result in:
    Params1(a = val1, b = null)
    Params2(a = null, c = nestedvalue)

  */
}

Extract query parameter names from json:

{
  "a": null,
  "b": {
      "a": null,
      "c": null
    }
}

Must result in three query parameters:

  • a
  • b.a
  • b.c

cc-jhr avatar Aug 11 '19 16:08 cc-jhr

Any plans regarding this feature?

atlatosPonga avatar Jun 25 '20 09:06 atlatosPonga

Hi @atlatosPonga, thank you for your interest in the project. There are currently no concrete plans for the implementation or the timing of the implementation. Pull requests are always welcome ;)

cc-jhr avatar Jun 25 '20 13:06 cc-jhr