Skip to content

[BUG][JAVA][MAVEN] java.time.OffsetDateTime cannot be cast to java.lang.String  #5256

@FloKaemmerer

Description

@FloKaemmerer

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Generation of client classes fails with class cast Exception while generation using maven Plugin.
Running mvn clean compile fails with

[ERROR] 
java.lang.RuntimeException: Could not process operation:
  Tag: class Tag {
    name: Process
    description: REST-Services.
    externalDocs: null
}
  Operation: getProcessUsingGET
  Resource: get /api/prozesse
  Schemas: {}
  Exception: java.time.OffsetDateTime cannot be cast to java.lang.String
openapi-generator version

4.2.3
(Happens also in earlier Versions of 4.x.x)

OpenAPI declaration file content or url

The Spec used: (its valid according to https://apitools.dev/swagger-parser/online/ and https://editor.swagger.io/ )

swagger: '2.0'
info:
  description: 'REST service'
  version: '2.1.9'
  title: REST
host: localhost
basePath: /
tags:
  - name: Process
    description: REST-Services.
paths:
  /api/prozesse:
    get:
      tags:
        - Process
      summary: Return a list of Process
      description: |
        Max response time MAX_RESPONSE_TIME_MS=20
      operationId: getProcessUsingGET
      produces:
        - application/json;charset=utf-8
      parameters:
        - name: dateFrom
          in: query
          description: Filters out Transactions before this date
          required: true
          type: string
          default: '2000-01-01T00:00:00.001Z'
          format: date-time
          allowEmptyValue: false
      responses:
        '200':
          description: OK
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Not Found
      security:
        - bearer: []
      deprecated: false
securityDefinitions:
  bearer:
    type: apiKey
    name: Authorization
    in: header

Used pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

	<modelVersion>4.0.0</modelVersion>
	<artifactId>failing-with-class-cast-exception</artifactId>
	<name>failing-with-class-cast-exception</name>
	<groupId>com.example</groupId>
	<version>0.0.1-SNAPSHOT</version>
	<build>
		<plugins>
			<plugin>
				<groupId>org.openapitools</groupId>
				<artifactId>openapi-generator-maven-plugin</artifactId>
				<version>4.2.3</version>
				<executions>
					<execution>
						<id>kto-privatkunde</id>
						<goals>
							<goal>generate</goal>
						</goals>
						<configuration>
							<inputSpec>process.yml</inputSpec>
							<generatorName>java</generatorName>
							<generateApiTests>false</generateApiTests>
							<generateModelTests>false</generateModelTests>
							<configOptions>
								<library>jersey2</library>
								<hideGenerationTimestamp>true</hideGenerationTimestamp>
								<delegatePattern>true</delegatePattern>
								<java8>java8</java8>
								<dateLibrary>java8</dateLibrary>
							</configOptions>
							<additionalProperties>failOnEmptyBeans=false</additionalProperties>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>
Command line used for generation

mvn clean compile

Steps to reproduce

Setup maven project and run mvn clean compile

Related issues/PRs
Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions