#### Bug Report Checklist
Description
The Java generator maps format: date-time-local to java.time.LocalDateTime, but the okhttp-gson library's JSON.mustache never registers a Gson TypeAdapter for LocalDateTime. It only registers adapters for Date, java.sql.Date, OffsetDateTime, LocalDate, and byte[], so Gson falls back to ReflectiveTypeAdapterFactory, which calls setAccessible(true) on java.time.LocalDateTime's private fields which throws:
com.google.gson.JsonIOException: Failed making field 'java.time.LocalDateTime#date' accessible; either increase its visibility or write a custom TypeAdapter for its declaring type.
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.time.LocalDate java.time.LocalDateTime.date accessible: module java.base does not "opens java.time" to unnamed module @71aa8854
Any spec with a field using format: date-time-local creates a client that throws the first time that field is deserialized.
Relevant source:
AbstractJavaCodegen.java:typeMapping.put("date-time-local", "LocalDateTime"); and importMapping.put("LocalDateTime", "java.time.LocalDateTime");
modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/JSON.mustache: adapter registrations in the static initializer; no LocalDateTime entry
openapi-generator version
7.24.0
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: date-time-local snippet
version: 1.0.0
paths:
/thing:
get:
operationId: getThing
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Thing'
components:
schemas:
Thing:
type: object
properties:
occurredAt:
type: string
format: date-time-local
Generation Details
openapi-generator-cli generate -i snippet.yml -g java --library okhttp-gson -o .
Steps to reproduce
- Generate the client with the spec and command above.
- Run the following to deserialize
{"occurredAt": "2025-09-29T01:23:00"} into Thing.
mvn -q -Dmaven.test.skip=true package
mvn -q dependency:build-classpath -Dmdep.outputFile=cp.txt
cat > Repro.java <<'EOF'
import org.openapitools.client.model.Thing;
public class Repro {
public static void main(String[] args) throws Exception {
System.out.println(Thing.fromJson("{\"occurredAt\":\"2025-09-29T01:23:00\"}"));
}
}
EOF
java -cp "target/classes:$(cat cp.txt)" Repro.java
Actual: JsonIOException / InaccessibleObjectException as above.
Expected: deserializes into a LocalDateTime.
Related issues/PRs
#13889
#23395
Suggest a fix
Add a LocalDateTimeTypeAdapter to the okhttp-gson JSON.mustache, mirroring the existing LocalDateTypeAdapter. I have this working and will open a PR shortly.
#### Bug Report Checklist
Description
The Java generator maps
format: date-time-localtojava.time.LocalDateTime, but theokhttp-gsonlibrary'sJSON.mustachenever registers a GsonTypeAdapterforLocalDateTime. It only registers adapters forDate,java.sql.Date,OffsetDateTime,LocalDate, andbyte[], so Gson falls back toReflectiveTypeAdapterFactory, which callssetAccessible(true)onjava.time.LocalDateTime's private fields which throws:Any spec with a field using
format: date-time-localcreates a client that throws the first time that field is deserialized.Relevant source:
AbstractJavaCodegen.java:typeMapping.put("date-time-local", "LocalDateTime");andimportMapping.put("LocalDateTime", "java.time.LocalDateTime");modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/JSON.mustache: adapter registrations in the static initializer; noLocalDateTimeentryopenapi-generator version
7.24.0
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
{"occurredAt": "2025-09-29T01:23:00"}intoThing.Actual:
JsonIOException/InaccessibleObjectExceptionas above.Expected: deserializes into a
LocalDateTime.Related issues/PRs
#13889
#23395
Suggest a fix
Add a
LocalDateTimeTypeAdapterto the okhttp-gsonJSON.mustache, mirroring the existingLocalDateTypeAdapter. I have this working and will open a PR shortly.