Openapi-generator: [BUG] [java] incompatible types: double cannot be converted to java.math.BigDecimal

Created on 26 Nov 2019  路  5Comments  路  Source: OpenAPITools/openapi-generator

hello i'm using version 4.2.1

my json is in the following format

Captura de tela de 2019-11-26 11-29-36

and the generated code looks like this

Captura de tela de 2019-11-26 11-26-18

this was an error at compile time because you can parse it year.

'incompatible types: double cannot be converted to java.math.BigDecimal'

Is there any way around this problem?

Java Bug

Most helpful comment

Closed via #8018

Please pull the latest master to give it a try.

Thanks for the PR by @bgong-mdsol

All 5 comments

馃憤 Thanks for opening this issue!
馃彿 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

I'm having the same issue using 4.2.3.

worked around this by using the following type mapping:

                            <typeMappings>
                                <typeMapping>number=java.lang.Double</typeMapping>
                            </typeMappings>

The work around suggested by @conet works well. In my case, I added it to the pom.xml file as shown below.

  <build>
    <plugins>
      <plugin>
        <groupId>org.openapitools</groupId>
        <artifactId>openapi-generator-maven-plugin</artifactId>
        <version>4.2.3</version>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <inputSpec>${project.basedir}/src/main/resources/openapi.yaml</inputSpec>
              <generatorName>spring</generatorName>
              <apiPackage>org.ogc.api</apiPackage>
              <modelPackage>org.ogc.model</modelPackage>
              <supportingFilesToGenerate>ApiUtil.java</supportingFilesToGenerate>
              <configOptions>
                <delegatePattern>true</delegatePattern>
              </configOptions>
              <typeMappings>
                <typeMapping>number=java.lang.Double</typeMapping>
              </typeMappings>
            </configuration>
          </execution>
        </executions>
      </plugin>

Closed via #8018

Please pull the latest master to give it a try.

Thanks for the PR by @bgong-mdsol

Was this page helpful?
0 / 5 - 0 ratings