xenoterracide
07/01/2019, 4:45 PMvar objectMapper: ObjectMapper = {
val mapper = ObjectMapper()
mapper.registerModules(JavaTimeModule(), KotlinModule())
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
mapper
}
is there a way to do an initialization block kind of like this? just init
? is there something more per property?Marc Knaup
07/01/2019, 4:46 PM()
to the end to execute immediately.Pere Casafont
07/01/2019, 4:47 PMval objectMapper: ObjectMapper = ObjectMapper().apply {
registerModules(JavaTimeModule(), KotlinModule())
disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
setSerializationInclusion(JsonInclude.Include.NON_NULL)
}
streetsofboston
07/01/2019, 4:47 PMvar objectMapper = ObjectMapper().apply {
registerModules(JavaTimeModule(), KotlinModule())
disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
setSerializationInclusion(JsonInclude.Include.NON_NULL)
}
Pere Casafont
07/01/2019, 4:47 PMMarc Knaup
07/01/2019, 4:47 PMval
and Anton has omitted the redundant variable type.
+1 for both, still a tie 😄Pere Casafont
07/01/2019, 4:49 PMval
everywhere you can and var
only when you really need to be able to alter its value in the future. In your use case var
smells a bit 😉xenoterracide
07/01/2019, 4:51 PMPere Casafont
07/01/2019, 4:51 PMMarc Knaup
07/01/2019, 4:54 PMxenoterracide
07/01/2019, 4:59 PM