Search code examples
kotlinmicronaut

Ignore property for type conversion of declarative client URI argument


I am implementing a declarative client in Micronaut that looks like this:

@Get("/dostuff{?requestObject*}")
fun getStuff(requestObject: MyRequestObject): String

My MyRequestObject is validated with Javax.Validation and looks like this:

data class MyRequestObject(val anything: String) {

    @AssertTrue
    fun isValid() = true
}

When I now send a request via the client the value from requestObject generates the following query /?anything=helloworld&valid=true. I need to exclude the value from the isValid function from the query.

Now I have two questions

  1. What is the mechanism that is used by Micronaut to "deserialize" the object?
  2. How can I achieve that the valid field is not included in the query?

Solution

  • The expansion of the URL takes place here: https://github.com/micronaut-projects/micronaut-core/blob/7cd78cf8b03cc78ac31bc2c262e86eae6edd58f0/http/src/main/java/io/micronaut/http/uri/UriTemplate.java#L202

    Either through the introspection api or reflection the class is inspected and converted to a map. Currently there is no way to exclude properties in this manner. Please file an issue to suggest improvement of this feature.