-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
Description
When using the kotlin-spring generator with useSpringBoot4=true and useJackson3=true, the generated application fails to start with the following error:
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under 'spring.jackson.serialization' to java.util.Map<tools.jackson.databind.SerializationFeature, java.lang.Boolean>:
Reason: failed to convert java.lang.String to tools.jackson.databind.SerializationFeature (caused by java.lang.IllegalArgumentException: No enum constant tools.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
Action:
Update your application's configuration. The following values are valid:
CLOSE_CLOSEABLE
EAGER_SERIALIZER_FETCH
FAIL_ON_EMPTY_BEANS
...
Root Cause: In Jackson 3.x (used by Spring Boot 4), the WRITE_DATES_AS_TIMESTAMPS feature was moved from SerializationFeature to DateTimeFeature. The property path changed from:
- Jackson 2.x:
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS - Jackson 3.x:
spring.jackson.datatype.datetime.WRITE_DATES_AS_TIMESTAMPS
The kotlin-spring generator template always outputs the Jackson 2.x path, even when useSpringBoot4=true.
Note: The JavaSpring generator already handles this correctly with conditional logic.
openapi-generator version
7.21.0 (also confirmed on latest master)
OpenAPI declaration file content or url
Any valid OpenAPI spec, minimal example:
openapi: 3.0.3
info:
title: Test API
version: 1.0.0
paths:
/ping:
get:
operationId: ping
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
message:
type: stringGeneration Details
openapi-generator-cli generate \
-i api.yaml \
-g kotlin-spring \
-o server \
--additional-properties=useSpringBoot4=true,useJackson3=trueSteps to reproduce
- Generate a kotlin-spring server with
useSpringBoot4=true - Build the project:
./gradlew build - Run the application:
./gradlew bootRun - Application fails to start with the error above
Related issues/PRs
- The
JavaSpringgenerator already has the fix: it uses conditional logic based onuseSpringBoot4inmodules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/application.mustache
Suggest a fix
The template at modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/application.mustache needs conditional logic based on useSpringBoot4:
Current (broken):
spring:
jackson:
serialization:
WRITE_DATES_AS_TIMESTAMPS: falseExpected:
spring:
jackson:
{{#useSpringBoot4}}
datatype:
datetime:
WRITE_DATES_AS_TIMESTAMPS: false
{{/useSpringBoot4}}
{{^useSpringBoot4}}
serialization:
WRITE_DATES_AS_TIMESTAMPS: false
{{/useSpringBoot4}}