, but that doesn't follow Spring conventions I suppose
h
Hamza GATTAL
05/03/2021, 5:07 PM
I'm converting a Java code to kotlin
š” 2
b
Ben
05/03/2021, 7:12 PM
@Emil Kantis Jackson will set non-nullable fields to null using reflection.
š£ 1
t
thanksforallthefish
05/04/2021, 5:35 AM
personally Iād rather have the json representation accepts nulls and being annotated with
@NotNull
than having the field not-nullable, it makes for easier and better error message given the stack I use (spring boot, web and validation).
@NotNull
generates a validation exception which I can treat as all other validations exceptions, which not-nullable field is a kotlin binding error, which needs special treatment. eg
Copy code
class SomeApiRepresentation(@get:NotNull aNotNullableField: String?)
the price of course is
!!
, but I am not a purist, and in this case
!!
is fine with me
t
Thomas
05/04/2021, 8:05 AM
I also would vote for @thanksforallthefishās approach, as a field with null value is a possible input and only validation may fail. You can have a look at bootify.io, it generates a REST controller for a Kotlin/Spring project