Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query Parameter based on an object #47

Open
cc-jhr opened this issue Aug 11, 2019 · 2 comments
Open

Query Parameter based on an object #47

cc-jhr opened this issue Aug 11, 2019 · 2 comments
Labels
Feature Request Feature request. Spring Relates to the SpringConverter

Comments

@cc-jhr
Copy link
Collaborator

cc-jhr commented Aug 11, 2019

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 cc-jhr added Spring Relates to the SpringConverter Feature Request Feature request. labels Aug 11, 2019
@atlatosPonga
Copy link

Any plans regarding this feature?

@cc-jhr
Copy link
Collaborator Author

cc-jhr commented Jun 25, 2020

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 ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Feature request. Spring Relates to the SpringConverter
Projects
None yet
Development

No branches or pull requests

2 participants