我正在使用yaml
文件生成将用于返回JSON
响应的类。
yaml
NextPaymentDueDate:
description: Date the next payment is due on the loan
type: string
example: '2018-07-04'
format: date
我正在使用swagger-codegen-maven-plugin
来生成这些类:
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>api-call</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>src/main/resources/search.yaml</inputSpec>
<language>java</language>
<dateLibrary>java8-localdatetime</dateLibrary>
<output>${project.basedir}</output>
<apiPackage>com.api</apiPackage>
<modelPackage>com.model</modelPackage>
<invokerPackage>com.client</invokerPackage>
</configuration>
</execution>
</executions>
</plugin>
在我的代码中:
@SerializedName("NextPaymentDueDate")
private LocalDate nextPaymentDueDate = null;
...
myObj.setNextPaymentDueDate(LocalDate.parse("2018-07-01"));
结果:
"nextPaymentDueDate": { <-- note lowercase
"year": 2018,
"month": "JULY",
"era": "CE",
"dayOfMonth": 1,
"dayOfWeek": "SUNDAY",
"dayOfYear": 182,
"leapYear": false,
"monthValue": 7,
"chronology": {
"id": "ISO",
"calendarType": "iso8601"
}
},
我需要它返回:
"nextPaymentDueDate": {
"2018-07-01"
},
我还添加了application.properties
:
spring.jackson.serialization.write-dates-as-timestamps=false
但这没做任何事情。