-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Java][Client] Use java8 OffsetDateTime for clients (#7190)
* use java8 OffsetDateTime for clients * use java8 OffsetDateTime for clients * fix javadoc * add javadoc to JavaTimeFormatter.mustache * add javadoc to JavaTimeFormatter.mustache * add javadoc to JavaTimeFormatter.mustache
- Loading branch information
Showing
24 changed files
with
452 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
modules/openapi-generator/src/main/resources/Java/JavaTimeFormatter.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{{>licenseInfo}} | ||
package {{invokerPackage}}; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
|
||
/** | ||
* Class that add parsing/formatting support for Java 8+ {@code OffsetDateTime} class. | ||
* It's generated for java clients when {@code AbstractJavaCodegen#dateLibrary} specified as {@code java8}. | ||
*/ | ||
{{>generatedAnnotation}} | ||
public class JavaTimeFormatter { | ||
private DateTimeFormatter offsetDateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME; | ||
/** | ||
* Get the date format used to parse/format {@code OffsetDateTime} parameters. | ||
* @return DateTimeFormatter | ||
*/ | ||
public DateTimeFormatter getOffsetDateTimeFormatter() { | ||
return offsetDateTimeFormatter; | ||
} | ||
|
||
/** | ||
* Set the date format used to parse/format {@code OffsetDateTime} parameters. | ||
* @param offsetDateTimeFormatter {@code DateTimeFormatter} | ||
*/ | ||
public void setOffsetDateTimeFormatter(DateTimeFormatter offsetDateTimeFormatter) { | ||
this.offsetDateTimeFormatter = offsetDateTimeFormatter; | ||
} | ||
|
||
/** | ||
* Parse the given string into {@code OffsetDateTime} object. | ||
* @param str String | ||
* @return {@code OffsetDateTime} | ||
*/ | ||
public OffsetDateTime parseOffsetDateTime(String str) { | ||
try { | ||
return OffsetDateTime.parse(str, offsetDateTimeFormatter); | ||
} catch (DateTimeParseException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
/** | ||
* Format the given {@code OffsetDateTime} object into string. | ||
* @param offsetDateTime {@code OffsetDateTime} | ||
* @return {@code OffsetDateTime} in string format | ||
*/ | ||
public String formatOffsetDateTime(OffsetDateTime offsetDateTime) { | ||
return offsetDateTimeFormatter.format(offsetDateTime); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
.../petstore/java/jersey2-java8/src/main/java/org/openapitools/client/JavaTimeFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* OpenAPI Petstore | ||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ | ||
* | ||
* The version of the OpenAPI document: 1.0.0 | ||
* | ||
* | ||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). | ||
* https://openapi-generator.tech | ||
* Do not edit the class manually. | ||
*/ | ||
|
||
package org.openapitools.client; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
|
||
/** | ||
* Class that add parsing/formatting support for Java 8+ {@code OffsetDateTime} class. | ||
* It's generated for java clients when {@code AbstractJavaCodegen#dateLibrary} specified as {@code java8}. | ||
*/ | ||
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") | ||
public class JavaTimeFormatter { | ||
|
||
private DateTimeFormatter offsetDateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME; | ||
|
||
/** | ||
* Get the date format used to parse/format {@code OffsetDateTime} parameters. | ||
* @return DateTimeFormatter | ||
*/ | ||
public DateTimeFormatter getOffsetDateTimeFormatter() { | ||
return offsetDateTimeFormatter; | ||
} | ||
|
||
/** | ||
* Set the date format used to parse/format {@code OffsetDateTime} parameters. | ||
* @param offsetDateTimeFormatter {@code DateTimeFormatter} | ||
*/ | ||
public void setOffsetDateTimeFormatter(DateTimeFormatter offsetDateTimeFormatter) { | ||
this.offsetDateTimeFormatter = offsetDateTimeFormatter; | ||
} | ||
|
||
/** | ||
* Parse the given string into {@code OffsetDateTime} object. | ||
* @param str String | ||
* @return {@code OffsetDateTime} | ||
*/ | ||
public OffsetDateTime parseOffsetDateTime(String str) { | ||
try { | ||
return OffsetDateTime.parse(str, offsetDateTimeFormatter); | ||
} catch (DateTimeParseException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
/** | ||
* Format the given {@code OffsetDateTime} object into string. | ||
* @param offsetDateTime {@code OffsetDateTime} | ||
* @return {@code OffsetDateTime} in string format | ||
*/ | ||
public String formatOffsetDateTime(OffsetDateTime offsetDateTime) { | ||
return offsetDateTimeFormatter.format(offsetDateTime); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.