forked from loafle/openapi-generator-original
Merge branch 'master' of https://github.com/swagger-api/swagger-codegen
This commit is contained in:
commit
ba3f2eafd5
@ -142,6 +142,10 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
||||
} else {
|
||||
LOGGER.error("Unknown library option (-l/--library): " + getLibrary());
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey("jackson") ) {
|
||||
supportingFiles.add(new SupportingFile("RFC3339DateFormat.mustache", invokerFolder, "RFC3339DateFormat.java"));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean usesAnyRetrofitLibrary() {
|
||||
|
@ -126,6 +126,8 @@ public class SpringCodegen extends AbstractJavaCodegen {
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "HomeController.java"));
|
||||
supportingFiles.add(new SupportingFile("swagger2SpringBoot.mustache",
|
||||
(sourceFolder + File.separator + basePackage).replace(".", java.io.File.separator), "Swagger2SpringBoot.java"));
|
||||
supportingFiles.add(new SupportingFile("RFC3339DateFormat.mustache",
|
||||
(sourceFolder + File.separator + basePackage).replace(".", java.io.File.separator), "RFC3339DateFormat.java"));
|
||||
supportingFiles.add(new SupportingFile("application.mustache",
|
||||
("src.main.resources").replace(".", java.io.File.separator), "application.properties"));
|
||||
}
|
||||
@ -136,6 +138,8 @@ public class SpringCodegen extends AbstractJavaCodegen {
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "WebMvcConfiguration.java"));
|
||||
supportingFiles.add(new SupportingFile("swaggerUiConfiguration.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "SwaggerUiConfiguration.java"));
|
||||
supportingFiles.add(new SupportingFile("RFC3339DateFormat.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "RFC3339DateFormat.java"));
|
||||
supportingFiles.add(new SupportingFile("application.properties",
|
||||
("src.main.resources").replace(".", java.io.File.separator), "swagger.properties"));
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import {{invokerPackage}}.auth.Authentication;
|
||||
import {{invokerPackage}}.auth.HttpBasicAuth;
|
||||
@ -96,12 +95,7 @@ public class ApiClient {
|
||||
}
|
||||
|
||||
public static DateFormat buildDefaultDateFormat() {
|
||||
// Use RFC3339 format for date and datetime.
|
||||
// See http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
|
||||
// Use UTC as the default time zone.
|
||||
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
return dateFormat;
|
||||
return new RFC3339DateFormat();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,21 @@
|
||||
{{>licenseInfo}}
|
||||
package {{invokerPackage}};
|
||||
|
||||
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
|
||||
import com.fasterxml.jackson.databind.util.ISO8601Utils;
|
||||
|
||||
import java.text.FieldPosition;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
public class RFC3339DateFormat extends ISO8601DateFormat {
|
||||
|
||||
// Same as ISO8601DateFormat but serializing milliseconds.
|
||||
@Override
|
||||
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
|
||||
String value = ISO8601Utils.format(date, true);
|
||||
toAppendTo.append(value);
|
||||
return toAppendTo;
|
||||
}
|
||||
|
||||
}
|
@ -136,6 +136,7 @@ public class ApiClient {
|
||||
objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
|
||||
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
objectMapper.setDateFormat(new RFC3339DateFormat());
|
||||
{{^java8}}
|
||||
objectMapper.registerModule(new JodaModule());
|
||||
{{/java8}}
|
||||
|
@ -8,7 +8,6 @@ import java.nio.charset.Charset;
|
||||
import java.util.*;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import feign.codec.EncodeException;
|
||||
import feign.codec.Encoder;
|
||||
@ -32,12 +31,8 @@ public class FormAwareEncoder implements Encoder {
|
||||
|
||||
public FormAwareEncoder(Encoder delegate) {
|
||||
this.delegate = delegate;
|
||||
// Use RFC3339 format for date and datetime.
|
||||
// See http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14
|
||||
this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
|
||||
this.dateFormat = new RFC3339DateFormat();;
|
||||
|
||||
// Use UTC as the default time zone.
|
||||
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
try {
|
||||
this.lineFeedBytes = LINE_FEED.getBytes(UTF_8);
|
||||
this.boundaryBytes = BOUNDARY.getBytes(UTF_8);
|
||||
|
@ -39,7 +39,6 @@ import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -70,14 +69,7 @@ public class ApiClient {
|
||||
json = new JSON();
|
||||
httpClient = buildHttpClient(debugging);
|
||||
|
||||
// Use RFC3339 format for date and datetime.
|
||||
// See http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14
|
||||
this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
|
||||
|
||||
// Use UTC as the default time zone.
|
||||
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
this.json.setDateFormat((DateFormat) dateFormat.clone());
|
||||
this.dateFormat = new RFC3339DateFormat();
|
||||
|
||||
// Set default User-Agent.
|
||||
setUserAgent("{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}Swagger-Codegen/{{{artifactVersion}}}/java{{/httpUserAgent}}");
|
||||
|
@ -24,6 +24,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
|
||||
mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
|
||||
mapper.setDateFormat(new RFC3339DateFormat());
|
||||
{{#java8}}
|
||||
mapper.registerModule(new JavaTimeModule());
|
||||
{{/java8}}
|
||||
|
@ -1,3 +1,5 @@
|
||||
springfox.documentation.swagger.v2.path=/api-docs
|
||||
server.contextPath={{^contextPath}}/{{/contextPath}}{{#contextPath}}{{contextPath}}{{/contextPath}}
|
||||
server.port={{serverPort}}
|
||||
server.port={{serverPort}}
|
||||
spring.jackson.date-format={{basePackage}}.RFC3339DateFormat
|
||||
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
|
@ -0,0 +1,20 @@
|
||||
package {{basePackage}};
|
||||
|
||||
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
|
||||
import com.fasterxml.jackson.databind.util.ISO8601Utils;
|
||||
|
||||
import java.text.FieldPosition;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
public class RFC3339DateFormat extends ISO8601DateFormat {
|
||||
|
||||
// Same as ISO8601DateFormat but serializing milliseconds.
|
||||
@Override
|
||||
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
|
||||
String value = ISO8601Utils.format(date, true);
|
||||
toAppendTo.append(value);
|
||||
return toAppendTo;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package {{configPackage}};
|
||||
|
||||
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
|
||||
import com.fasterxml.jackson.databind.util.ISO8601Utils;
|
||||
|
||||
import java.text.FieldPosition;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
public class RFC3339DateFormat extends ISO8601DateFormat {
|
||||
|
||||
// Same as ISO8601DateFormat but serializing milliseconds.
|
||||
@Override
|
||||
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
|
||||
String value = ISO8601Utils.format(date, true);
|
||||
toAppendTo.append(value);
|
||||
return toAppendTo;
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +1,21 @@
|
||||
package {{configPackage}};
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = "{{apiPackage}}")
|
||||
@ -51,4 +58,14 @@ public class SwaggerUiConfiguration extends WebMvcConfigurerAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||
.dateFormat( new RFC3339DateFormat())
|
||||
.build();
|
||||
converters.add(new MappingJackson2HttpMessageConverter(objectMapper));
|
||||
super.configureMessageConverters(converters);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -132,6 +132,7 @@ public class ApiClient {
|
||||
objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
|
||||
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
objectMapper.setDateFormat(new RFC3339DateFormat());
|
||||
objectMapper.registerModule(new JodaModule());
|
||||
return objectMapper;
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import java.nio.charset.Charset;
|
||||
import java.util.*;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import feign.codec.EncodeException;
|
||||
import feign.codec.Encoder;
|
||||
@ -32,12 +31,8 @@ public class FormAwareEncoder implements Encoder {
|
||||
|
||||
public FormAwareEncoder(Encoder delegate) {
|
||||
this.delegate = delegate;
|
||||
// Use RFC3339 format for date and datetime.
|
||||
// See http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14
|
||||
this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
|
||||
this.dateFormat = new RFC3339DateFormat();;
|
||||
|
||||
// Use UTC as the default time zone.
|
||||
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
try {
|
||||
this.lineFeedBytes = LINE_FEED.getBytes(UTF_8);
|
||||
this.boundaryBytes = BOUNDARY.getBytes(UTF_8);
|
||||
|
@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Swagger 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: \" \\
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
* Contact: apiteam@swagger.io
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen.git
|
||||
* Do not edit the class manually.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.swagger.client;
|
||||
|
||||
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
|
||||
import com.fasterxml.jackson.databind.util.ISO8601Utils;
|
||||
|
||||
import java.text.FieldPosition;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
public class RFC3339DateFormat extends ISO8601DateFormat {
|
||||
|
||||
// Same as ISO8601DateFormat but serializing milliseconds.
|
||||
@Override
|
||||
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
|
||||
String value = ISO8601Utils.format(date, true);
|
||||
toAppendTo.append(value);
|
||||
return toAppendTo;
|
||||
}
|
||||
|
||||
}
|
@ -58,7 +58,6 @@ import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import io.swagger.client.auth.Authentication;
|
||||
import io.swagger.client.auth.HttpBasicAuth;
|
||||
@ -109,12 +108,7 @@ public class ApiClient {
|
||||
}
|
||||
|
||||
public static DateFormat buildDefaultDateFormat() {
|
||||
// Use RFC3339 format for date and datetime.
|
||||
// See http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
|
||||
// Use UTC as the default time zone.
|
||||
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
return dateFormat;
|
||||
return new RFC3339DateFormat();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Swagger 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: \" \\
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
* Contact: apiteam@swagger.io
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen.git
|
||||
* Do not edit the class manually.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.swagger.client;
|
||||
|
||||
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
|
||||
import com.fasterxml.jackson.databind.util.ISO8601Utils;
|
||||
|
||||
import java.text.FieldPosition;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
public class RFC3339DateFormat extends ISO8601DateFormat {
|
||||
|
||||
// Same as ISO8601DateFormat but serializing milliseconds.
|
||||
@Override
|
||||
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
|
||||
String value = ISO8601Utils.format(date, true);
|
||||
toAppendTo.append(value);
|
||||
return toAppendTo;
|
||||
}
|
||||
|
||||
}
|
@ -34,8 +34,8 @@ import io.swagger.client.Pair;
|
||||
|
||||
import io.swagger.client.model.Client;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.DateTime;
|
||||
import java.math.BigDecimal;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -33,8 +33,8 @@ import io.swagger.client.model.*;
|
||||
import io.swagger.client.Pair;
|
||||
|
||||
import io.swagger.client.model.Pet;
|
||||
import java.io.File;
|
||||
import io.swagger.client.model.ModelApiResponse;
|
||||
import java.io.File;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -39,7 +39,6 @@ import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -70,14 +69,7 @@ public class ApiClient {
|
||||
json = new JSON();
|
||||
httpClient = buildHttpClient(debugging);
|
||||
|
||||
// Use RFC3339 format for date and datetime.
|
||||
// See http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14
|
||||
this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
|
||||
|
||||
// Use UTC as the default time zone.
|
||||
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
this.json.setDateFormat((DateFormat) dateFormat.clone());
|
||||
this.dateFormat = new RFC3339DateFormat();
|
||||
|
||||
// Set default User-Agent.
|
||||
setUserAgent("Swagger-Codegen/1.0.0/java");
|
||||
|
@ -19,6 +19,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
|
||||
mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
|
||||
mapper.setDateFormat(new RFC3339DateFormat());
|
||||
mapper.registerModule(new JodaModule());
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Swagger 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: \" \\
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
* Contact: apiteam@swagger.io
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen.git
|
||||
* Do not edit the class manually.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.swagger.client;
|
||||
|
||||
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
|
||||
import com.fasterxml.jackson.databind.util.ISO8601Utils;
|
||||
|
||||
import java.text.FieldPosition;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
public class RFC3339DateFormat extends ISO8601DateFormat {
|
||||
|
||||
// Same as ISO8601DateFormat but serializing milliseconds.
|
||||
@Override
|
||||
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
|
||||
String value = ISO8601Utils.format(date, true);
|
||||
toAppendTo.append(value);
|
||||
return toAppendTo;
|
||||
}
|
||||
|
||||
}
|
@ -1,8 +1,11 @@
|
||||
package io.swagger.client;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ser.std.SqlDateSerializer;
|
||||
import io.swagger.client.model.Order;
|
||||
|
||||
import java.lang.Exception;
|
||||
import java.sql.Date;
|
||||
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
@ -17,7 +20,7 @@ public class JSONTest {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
json = new JSON();
|
||||
json = new ApiClient().getJSON();
|
||||
order = new Order();
|
||||
}
|
||||
|
||||
@ -42,4 +45,18 @@ public class JSONTest {
|
||||
Order o = json.getContext(null).readValue(str, Order.class);
|
||||
assertEquals(dateStr, dateFormat.print(o.getShipDate()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSqlDateSerialization() throws Exception {
|
||||
String str = json.getContext(null).writeValueAsString(new java.sql.Date(10));
|
||||
assertEquals("\"1970-01-01\"", str);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSqlDateDeserialization() throws Exception {
|
||||
final String str = "1970-01-01";
|
||||
java.sql.Date date = json.getContext(null).readValue("\"" + str + "\"", java.sql.Date.class);
|
||||
assertEquals(date.toString(), str);
|
||||
}
|
||||
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package io.swagger.api;
|
||||
|
||||
import io.swagger.model.Client;
|
||||
import java.time.LocalDate;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.LocalDate;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package io.swagger.api;
|
||||
|
||||
import io.swagger.model.Pet;
|
||||
import java.io.File;
|
||||
import io.swagger.model.ModelApiResponse;
|
||||
import java.io.File;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
@ -0,0 +1,20 @@
|
||||
package io.swagger.configuration;
|
||||
|
||||
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
|
||||
import com.fasterxml.jackson.databind.util.ISO8601Utils;
|
||||
|
||||
import java.text.FieldPosition;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
public class RFC3339DateFormat extends ISO8601DateFormat {
|
||||
|
||||
// Same as ISO8601DateFormat but serializing milliseconds.
|
||||
@Override
|
||||
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
|
||||
String value = ISO8601Utils.format(date, true);
|
||||
toAppendTo.append(value);
|
||||
return toAppendTo;
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +1,21 @@
|
||||
package io.swagger.configuration;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = "io.swagger.api")
|
||||
@ -51,4 +58,14 @@ public class SwaggerUiConfiguration extends WebMvcConfigurerAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||
.dateFormat( new RFC3339DateFormat())
|
||||
.build();
|
||||
converters.add(new MappingJackson2HttpMessageConverter(objectMapper));
|
||||
super.configureMessageConverters(converters);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,8 +2,8 @@ package io.swagger.api;
|
||||
|
||||
import io.swagger.model.Client;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.DateTime;
|
||||
import java.math.BigDecimal;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -2,8 +2,8 @@ package io.swagger.api;
|
||||
|
||||
import io.swagger.model.Client;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.DateTime;
|
||||
import java.math.BigDecimal;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package io.swagger.api;
|
||||
|
||||
import io.swagger.model.Pet;
|
||||
import java.io.File;
|
||||
import io.swagger.model.ModelApiResponse;
|
||||
import java.io.File;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package io.swagger.api;
|
||||
|
||||
import io.swagger.model.Pet;
|
||||
import java.io.File;
|
||||
import io.swagger.model.ModelApiResponse;
|
||||
import java.io.File;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
|
||||
|
@ -0,0 +1,20 @@
|
||||
package io.swagger.configuration;
|
||||
|
||||
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
|
||||
import com.fasterxml.jackson.databind.util.ISO8601Utils;
|
||||
|
||||
import java.text.FieldPosition;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
public class RFC3339DateFormat extends ISO8601DateFormat {
|
||||
|
||||
// Same as ISO8601DateFormat but serializing milliseconds.
|
||||
@Override
|
||||
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
|
||||
String value = ISO8601Utils.format(date, true);
|
||||
toAppendTo.append(value);
|
||||
return toAppendTo;
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +1,21 @@
|
||||
package io.swagger.configuration;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = "io.swagger.api")
|
||||
@ -51,4 +58,14 @@ public class SwaggerUiConfiguration extends WebMvcConfigurerAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||
.dateFormat( new RFC3339DateFormat())
|
||||
.build();
|
||||
converters.add(new MappingJackson2HttpMessageConverter(objectMapper));
|
||||
super.configureMessageConverters(converters);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package io.swagger;
|
||||
|
||||
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
|
||||
import com.fasterxml.jackson.databind.util.ISO8601Utils;
|
||||
|
||||
import java.text.FieldPosition;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
public class RFC3339DateFormat extends ISO8601DateFormat {
|
||||
|
||||
// Same as ISO8601DateFormat but serializing milliseconds.
|
||||
@Override
|
||||
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
|
||||
String value = ISO8601Utils.format(date, true);
|
||||
toAppendTo.append(value);
|
||||
return toAppendTo;
|
||||
}
|
||||
|
||||
}
|
@ -2,8 +2,8 @@ package io.swagger.api;
|
||||
|
||||
import io.swagger.model.Client;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.DateTime;
|
||||
import java.math.BigDecimal;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -2,8 +2,8 @@ package io.swagger.api;
|
||||
|
||||
import io.swagger.model.Client;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.DateTime;
|
||||
import java.math.BigDecimal;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package io.swagger.api;
|
||||
|
||||
import io.swagger.model.Pet;
|
||||
import java.io.File;
|
||||
import io.swagger.model.ModelApiResponse;
|
||||
import java.io.File;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package io.swagger.api;
|
||||
|
||||
import io.swagger.model.Pet;
|
||||
import java.io.File;
|
||||
import io.swagger.model.ModelApiResponse;
|
||||
import java.io.File;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
springfox.documentation.swagger.v2.path=/api-docs
|
||||
server.contextPath=/v2
|
||||
server.port=8080
|
||||
server.port=8080
|
||||
spring.jackson.date-format=io.swagger.RFC3339DateFormat
|
||||
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
|
Loading…
x
Reference in New Issue
Block a user