mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-03 00:43:46 +00:00
Co-authored-by: Christian Beikov <christian.beikov@gmail.com>
This commit is contained in:
@@ -103,6 +103,8 @@ src/main/java/org/openapitools/client/Configuration.java
|
||||
src/main/java/org/openapitools/client/JSON.java
|
||||
src/main/java/org/openapitools/client/Pair.java
|
||||
src/main/java/org/openapitools/client/RFC3339DateFormat.java
|
||||
src/main/java/org/openapitools/client/RFC3339InstantDeserializer.java
|
||||
src/main/java/org/openapitools/client/RFC3339JavaTimeModule.java
|
||||
src/main/java/org/openapitools/client/ServerConfiguration.java
|
||||
src/main/java/org/openapitools/client/ServerVariable.java
|
||||
src/main/java/org/openapitools/client/api/AnotherFakeApi.java
|
||||
|
||||
@@ -203,6 +203,7 @@ public class ApiClient {
|
||||
mapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
|
||||
mapper.registerModule(new JavaTimeModule());
|
||||
mapper.registerModule(new JsonNullableModule());
|
||||
mapper.registerModule(new RFC3339JavaTimeModule());
|
||||
return mapper;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.Temporal;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer;
|
||||
|
||||
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.12.0-SNAPSHOT")
|
||||
public class RFC3339InstantDeserializer<T extends Temporal> extends InstantDeserializer<T> {
|
||||
|
||||
private final static boolean DEFAULT_NORMALIZE_ZONE_ID = JavaTimeFeature.NORMALIZE_DESERIALIZED_ZONE_ID.enabledByDefault();
|
||||
private final static boolean DEFAULT_ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS
|
||||
= JavaTimeFeature.ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS.enabledByDefault();
|
||||
|
||||
public static final RFC3339InstantDeserializer<Instant> INSTANT = new RFC3339InstantDeserializer<>(
|
||||
Instant.class, DateTimeFormatter.ISO_INSTANT,
|
||||
Instant::from,
|
||||
a -> Instant.ofEpochMilli( a.value ),
|
||||
a -> Instant.ofEpochSecond( a.integer, a.fraction ),
|
||||
null,
|
||||
true, // yes, replace zero offset with Z
|
||||
DEFAULT_NORMALIZE_ZONE_ID,
|
||||
DEFAULT_ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS
|
||||
);
|
||||
|
||||
public static final RFC3339InstantDeserializer<OffsetDateTime> OFFSET_DATE_TIME = new RFC3339InstantDeserializer<>(
|
||||
OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME,
|
||||
OffsetDateTime::from,
|
||||
a -> OffsetDateTime.ofInstant( Instant.ofEpochMilli( a.value ), a.zoneId ),
|
||||
a -> OffsetDateTime.ofInstant( Instant.ofEpochSecond( a.integer, a.fraction ), a.zoneId ),
|
||||
(d, z) -> ( d.isEqual( OffsetDateTime.MIN ) || d.isEqual( OffsetDateTime.MAX ) ?
|
||||
d :
|
||||
d.withOffsetSameInstant( z.getRules().getOffset( d.toLocalDateTime() ) ) ),
|
||||
true, // yes, replace zero offset with Z
|
||||
DEFAULT_NORMALIZE_ZONE_ID,
|
||||
DEFAULT_ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS
|
||||
);
|
||||
|
||||
public static final RFC3339InstantDeserializer<ZonedDateTime> ZONED_DATE_TIME = new RFC3339InstantDeserializer<>(
|
||||
ZonedDateTime.class, DateTimeFormatter.ISO_ZONED_DATE_TIME,
|
||||
ZonedDateTime::from,
|
||||
a -> ZonedDateTime.ofInstant( Instant.ofEpochMilli( a.value ), a.zoneId ),
|
||||
a -> ZonedDateTime.ofInstant( Instant.ofEpochSecond( a.integer, a.fraction ), a.zoneId ),
|
||||
ZonedDateTime::withZoneSameInstant,
|
||||
false, // keep zero offset and Z separate since zones explicitly supported
|
||||
DEFAULT_NORMALIZE_ZONE_ID,
|
||||
DEFAULT_ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS
|
||||
);
|
||||
|
||||
protected RFC3339InstantDeserializer(
|
||||
Class<T> supportedType,
|
||||
DateTimeFormatter formatter,
|
||||
Function<TemporalAccessor, T> parsedToValue,
|
||||
Function<FromIntegerArguments, T> fromMilliseconds,
|
||||
Function<FromDecimalArguments, T> fromNanoseconds,
|
||||
BiFunction<T, ZoneId, T> adjust,
|
||||
boolean replaceZeroOffsetAsZ,
|
||||
boolean normalizeZoneId,
|
||||
boolean readNumericStringsAsTimestamp) {
|
||||
super(
|
||||
supportedType,
|
||||
formatter,
|
||||
parsedToValue,
|
||||
fromMilliseconds,
|
||||
fromNanoseconds,
|
||||
adjust,
|
||||
replaceZeroOffsetAsZ,
|
||||
normalizeZoneId,
|
||||
readNumericStringsAsTimestamp
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected T _fromString(JsonParser p, DeserializationContext ctxt, String string0) throws IOException {
|
||||
return super._fromString(p, ctxt, string0.replace( ' ', 'T' ));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.Instant;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
|
||||
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.12.0-SNAPSHOT")
|
||||
public class RFC3339JavaTimeModule extends SimpleModule {
|
||||
|
||||
public RFC3339JavaTimeModule() {
|
||||
super("RFC3339JavaTimeModule");
|
||||
|
||||
addDeserializer(Instant.class, RFC3339InstantDeserializer.INSTANT);
|
||||
addDeserializer(OffsetDateTime.class, RFC3339InstantDeserializer.OFFSET_DATE_TIME);
|
||||
addDeserializer(ZonedDateTime.class, RFC3339InstantDeserializer.ZONED_DATE_TIME);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user