6

I am passing two headers in controller as below

@Header("x-correlationId") String correlationId,
@Header(name = "x-consumedBy") String consumedBy

where x-correlationId is mandatory and x-consumedBy is optional. I am not able to specify this.

In Spring we can specify required=false.

Tell us what happens instead.
It is taking both as mandatory.

If I specify @Nullable then it is always taking the value as null even if I pass the value

correlationId::12345:consumedBy:null
Ryuzaki L
  • 37,302
  • 12
  • 68
  • 98
Amaresh
  • 61
  • 2

2 Answers2

4

@Nullable is the preferred way to flag an argument as allowing nulls. If that isn't working for you then there must be something else at play that I can't tell from the information provided. It definitely does work, we have many tests that assert that.

James Kleeh
  • 12,094
  • 5
  • 34
  • 61
3

By default @Header params are mandatory, but to make x-consumedBy as an optional header you can set defaultValue

fun index(@Header("x-correlationId") xCorrelationId :String,
          @Header("x-consumedBy",defaultValue = "") xConsumedBy :String): String {
    
}
Ryuzaki L
  • 37,302
  • 12
  • 68
  • 98