forked from loafle/openapi-generator-original
[Java][jersey2] Fix Java compiler warnings (#6605)
* Mustache template should use invokerPackage tag to generate import * fix typo, fix script issue, add log statement for troubleshooting * Add java jersey2 samples with OpenAPI doc that has HTTP signature security scheme * Add sample for Java jersey2 and HTTP signature scheme * Add unit test for oneOf schema deserialization * Add unit test for oneOf schema deserialization * Add log statements * Add profile for jersey2 * Temporarily disable unit test * Temporarily disable unit test * support for discriminator in jersey2 * fix typo in pom.xml * disable unit test because jersey2 deserialization is broken * disable unit test because jersey2 deserialization is broken * fix duplicate jersey2 samples * fix duplicate jersey2 samples * Add code comments * fix duplicate artifact id * fix duplicate jersey2 samples * run samples scripts * resolve merge conflicts * Add unit tests * fix unit tests * continue implementation of discriminator lookup * throw deserialization exception when value is null and schema does not allow null value * continue implementation of compose schema * continue implementation of compose schema * continue implementation of compose schema * Add more unit tests * Add unit tests for anyOf * Add unit tests * [java][jersey2] Add support for discriminator, fix nullable typo and nullable deserialization (#6495) * Mustache template should use invokerPackage tag to generate import * fix typo, fix script issue, add log statement for troubleshooting * Add java jersey2 samples with OpenAPI doc that has HTTP signature security scheme * Add sample for Java jersey2 and HTTP signature scheme * Add unit test for oneOf schema deserialization * Add unit test for oneOf schema deserialization * Add log statements * Add profile for jersey2 * Temporarily disable unit test * Temporarily disable unit test * support for discriminator in jersey2 * fix typo in pom.xml * disable unit test because jersey2 deserialization is broken * disable unit test because jersey2 deserialization is broken * fix duplicate jersey2 samples * fix duplicate jersey2 samples * Add code comments * fix duplicate artifact id * fix duplicate jersey2 samples * run samples scripts * resolve merge conflicts * Add unit tests * fix unit tests * continue implementation of discriminator lookup * throw deserialization exception when value is null and schema does not allow null value * continue implementation of compose schema * continue implementation of compose schema * continue implementation of compose schema * Add more unit tests * Add unit tests for anyOf * Add unit tests Co-authored-by: Vikrant Balyan (vvb) <vvb@cisco.com> * update samples * add tests to oas3 java jersey2 petstore * Fix 'method too big' error with generated code * resolve merge conflicts * comment out jersey2 ensure uptodate * fix compiler warnings * Jersey2 supports additional properties with composed schema (#6523) * Mustache template should use invokerPackage tag to generate import * fix typo, fix script issue, add log statement for troubleshooting * Add java jersey2 samples with OpenAPI doc that has HTTP signature security scheme * Add sample for Java jersey2 and HTTP signature scheme * Add unit test for oneOf schema deserialization * Add unit test for oneOf schema deserialization * Add log statements * Add profile for jersey2 * Temporarily disable unit test * Temporarily disable unit test * support for discriminator in jersey2 * fix typo in pom.xml * disable unit test because jersey2 deserialization is broken * disable unit test because jersey2 deserialization is broken * fix duplicate jersey2 samples * fix duplicate jersey2 samples * Add code comments * fix duplicate artifact id * fix duplicate jersey2 samples * run samples scripts * resolve merge conflicts * Add unit tests * fix unit tests * continue implementation of discriminator lookup * throw deserialization exception when value is null and schema does not allow null value * continue implementation of compose schema * continue implementation of compose schema * continue implementation of compose schema * Add more unit tests * Add unit tests for anyOf * Add unit tests * Set supportsAdditionalPropertiesWithComposedSchema to true for Java jersey2 * Support additional properties as nested field * Support additional properties as nested field * add code comments * add customer deserializer * Fix 'method too big' error with generated code * resolve merge conflicts Co-authored-by: Vikrant Balyan (vvb) <vvb@cisco.com> * [Jersey2] Fix code generation of 'registerDiscriminator' method for large models (#6535) * Mustache template should use invokerPackage tag to generate import * fix typo, fix script issue, add log statement for troubleshooting * Add java jersey2 samples with OpenAPI doc that has HTTP signature security scheme * Add sample for Java jersey2 and HTTP signature scheme * Add unit test for oneOf schema deserialization * Add unit test for oneOf schema deserialization * Add log statements * Add profile for jersey2 * Temporarily disable unit test * Temporarily disable unit test * support for discriminator in jersey2 * fix typo in pom.xml * disable unit test because jersey2 deserialization is broken * disable unit test because jersey2 deserialization is broken * fix duplicate jersey2 samples * fix duplicate jersey2 samples * Add code comments * fix duplicate artifact id * fix duplicate jersey2 samples * run samples scripts * resolve merge conflicts * Add unit tests * fix unit tests * continue implementation of discriminator lookup * throw deserialization exception when value is null and schema does not allow null value * continue implementation of compose schema * continue implementation of compose schema * continue implementation of compose schema * Add more unit tests * Add unit tests for anyOf * Add unit tests * Fix 'method too big' error with generated code * resolve merge conflicts Co-authored-by: Vikrant Balyan (vvb) <vvb@cisco.com> * Add unit test for date time * Add unit test for date time * update samples * comment out tests * support additional properties in serialize and deserialize * add discriminator lookup * remove oneof/anyof logic in apilcient * add serializer to mammal.java * add serialize to oneOf model * add serializer to anyof model * comment out test cases that are subject to further discussion * add back files * update configs, samples * resolve merge conflicts Co-authored-by: Vikrant Balyan (vvb) <vvb@cisco.com> Co-authored-by: William Cheng <wing328hk@gmail.com>
This commit is contained in:
parent
0b561d6075
commit
4bbe3cdbc9
@ -84,10 +84,10 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
* @param node The input data.
|
||||
* @param modelClass The class that contains the discriminator mappings.
|
||||
*/
|
||||
public static Class getClassForElement(JsonNode node, Class modelClass) {
|
||||
public static Class<?> getClassForElement(JsonNode node, Class<?> modelClass) {
|
||||
ClassDiscriminatorMapping cdm = modelDiscriminators.get(modelClass);
|
||||
if (cdm != null) {
|
||||
return cdm.getClassForElement(node, new HashSet<Class>());
|
||||
return cdm.getClassForElement(node, new HashSet<Class<?>>());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -97,17 +97,17 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
*/
|
||||
private static class ClassDiscriminatorMapping {
|
||||
// The model class name.
|
||||
Class modelClass;
|
||||
Class<?> modelClass;
|
||||
// The name of the discriminator property.
|
||||
String discriminatorName;
|
||||
// The discriminator mappings for a model class.
|
||||
Map<String, Class> discriminatorMappings;
|
||||
Map<String, Class<?>> discriminatorMappings;
|
||||
|
||||
// Constructs a new class discriminator.
|
||||
ClassDiscriminatorMapping(Class cls, String propertyName, Map<String, Class> mappings) {
|
||||
ClassDiscriminatorMapping(Class<?> cls, String propertyName, Map<String, Class<?>> mappings) {
|
||||
modelClass = cls;
|
||||
discriminatorName = propertyName;
|
||||
discriminatorMappings = new HashMap<String, Class>();
|
||||
discriminatorMappings = new HashMap<String, Class<?>>();
|
||||
if (mappings != null) {
|
||||
discriminatorMappings.putAll(mappings);
|
||||
}
|
||||
@ -143,7 +143,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
* @param node The input data.
|
||||
* @param visitedClasses The set of classes that have already been visited.
|
||||
*/
|
||||
Class getClassForElement(JsonNode node, Set<Class> visitedClasses) {
|
||||
Class<?> getClassForElement(JsonNode node, Set<Class<?>> visitedClasses) {
|
||||
if (visitedClasses.contains(modelClass)) {
|
||||
// Class has already been visited.
|
||||
return null;
|
||||
@ -153,11 +153,11 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
if (discrValue == null) {
|
||||
return null;
|
||||
}
|
||||
Class cls = discriminatorMappings.get(discrValue);
|
||||
Class<?> cls = discriminatorMappings.get(discrValue);
|
||||
// It may not be sufficient to return this cls directly because that target class
|
||||
// may itself be a composed schema, possibly with its own discriminator.
|
||||
visitedClasses.add(modelClass);
|
||||
for (Class childClass : discriminatorMappings.values()) {
|
||||
for (Class<?> childClass : discriminatorMappings.values()) {
|
||||
ClassDiscriminatorMapping childCdm = modelDiscriminators.get(childClass);
|
||||
if (childCdm == null) {
|
||||
continue;
|
||||
@ -170,7 +170,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
}
|
||||
if (childCdm != null) {
|
||||
// Recursively traverse the discriminator mappings.
|
||||
Class childDiscr = childCdm.getClassForElement(node, visitedClasses);
|
||||
Class<?> childDiscr = childCdm.getClassForElement(node, visitedClasses);
|
||||
if (childDiscr != null) {
|
||||
return childDiscr;
|
||||
}
|
||||
@ -189,7 +189,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
* @param modelClass A OpenAPI model class.
|
||||
* @param inst The instance object.
|
||||
*/
|
||||
public static boolean isInstanceOf(Class modelClass, Object inst, Set<Class> visitedClasses) {
|
||||
public static boolean isInstanceOf(Class<?> modelClass, Object inst, Set<Class<?>> visitedClasses) {
|
||||
if (modelClass.isInstance(inst)) {
|
||||
// This handles the 'allOf' use case with single parent inheritance.
|
||||
return true;
|
||||
@ -216,12 +216,12 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
/**
|
||||
* A map of discriminators for all model classes.
|
||||
*/
|
||||
private static Map<Class, ClassDiscriminatorMapping> modelDiscriminators = new HashMap<Class, ClassDiscriminatorMapping>();
|
||||
private static Map<Class<?>, ClassDiscriminatorMapping> modelDiscriminators = new HashMap<Class<?>, ClassDiscriminatorMapping>();
|
||||
|
||||
/**
|
||||
* A map of oneOf/anyOf descendants for each model class.
|
||||
*/
|
||||
private static Map<Class, Map<String, GenericType>> modelDescendants = new HashMap<Class, Map<String, GenericType>>();
|
||||
private static Map<Class<?>, Map<String, GenericType>> modelDescendants = new HashMap<Class<?>, Map<String, GenericType>>();
|
||||
|
||||
/**
|
||||
* Register a model class discriminator.
|
||||
@ -230,7 +230,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
* @param discriminatorPropertyName the name of the discriminator property
|
||||
* @param mappings a map with the discriminator mappings.
|
||||
*/
|
||||
public static void registerDiscriminator(Class modelClass, String discriminatorPropertyName, Map<String, Class> mappings) {
|
||||
public static void registerDiscriminator(Class<?> modelClass, String discriminatorPropertyName, Map<String, Class<?>> mappings) {
|
||||
ClassDiscriminatorMapping m = new ClassDiscriminatorMapping(modelClass, discriminatorPropertyName, mappings);
|
||||
modelDiscriminators.put(modelClass, m);
|
||||
}
|
||||
@ -241,7 +241,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
* @param modelClass the model class
|
||||
* @param descendants a map of oneOf/anyOf descendants.
|
||||
*/
|
||||
public static void registerDescendants(Class modelClass, Map<String, GenericType> descendants) {
|
||||
public static void registerDescendants(Class<?> modelClass, Map<String, GenericType> descendants) {
|
||||
modelDescendants.put(modelClass, descendants);
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
|
||||
Object deserialized = null;
|
||||
{{#discriminator}}
|
||||
Class cls = JSON.getClassForElement(tree, {{classname}}.class);
|
||||
Class<?> cls = JSON.getClassForElement(tree, {{classname}}.class);
|
||||
if (cls != null) {
|
||||
// When the OAS schema includes a discriminator, use the discriminator value to
|
||||
// discriminate the anyOf schemas.
|
||||
@ -115,7 +115,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
return null;
|
||||
{{/isNullable}}
|
||||
{{^isNullable}}
|
||||
throw new JsonMappingException("{{classname}} cannot be null");
|
||||
throw new JsonMappingException(ctxt.getParser(), "{{classname}} cannot be null");
|
||||
{{/isNullable}}
|
||||
}
|
||||
}
|
||||
@ -153,7 +153,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
JSON.registerDescendants({{classname}}.class, Collections.unmodifiableMap(schemas));
|
||||
{{#discriminator}}
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class> mappings = new HashMap<String, Class>();
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
{{#mappedModels}}
|
||||
mappings.put("{{mappingName}}", {{modelName}}.class);
|
||||
{{/mappedModels}}
|
||||
@ -177,7 +177,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
|
||||
{{/isNullable}}
|
||||
{{#anyOf}}
|
||||
if (JSON.isInstanceOf({{{.}}}.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf({{{.}}}.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
return null;
|
||||
{{/isNullable}}
|
||||
{{^isNullable}}
|
||||
throw new JsonMappingException("{{classname}} cannot be null");
|
||||
throw new JsonMappingException(ctxt.getParser(), "{{classname}} cannot be null");
|
||||
{{/isNullable}}
|
||||
}
|
||||
}
|
||||
@ -166,7 +166,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
JSON.registerDescendants({{classname}}.class, Collections.unmodifiableMap(schemas));
|
||||
{{#discriminator}}
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class> mappings = new HashMap<String, Class>();
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
{{#mappedModels}}
|
||||
mappings.put("{{mappingName}}", {{modelName}}.class);
|
||||
{{/mappedModels}}
|
||||
@ -197,7 +197,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
|
||||
{{/isNullable}}
|
||||
{{#oneOf}}
|
||||
if (JSON.isInstanceOf({{{.}}}.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf({{{.}}}.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
@ -377,7 +377,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#vendorE
|
||||
{{#discriminator}}
|
||||
static {
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class> mappings = new HashMap<String, Class>();
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
{{#mappedModels}}
|
||||
mappings.put("{{mappingName}}", {{modelName}}.class);
|
||||
{{/mappedModels}}
|
||||
|
@ -59,10 +59,10 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
* @param node The input data.
|
||||
* @param modelClass The class that contains the discriminator mappings.
|
||||
*/
|
||||
public static Class getClassForElement(JsonNode node, Class modelClass) {
|
||||
public static Class<?> getClassForElement(JsonNode node, Class<?> modelClass) {
|
||||
ClassDiscriminatorMapping cdm = modelDiscriminators.get(modelClass);
|
||||
if (cdm != null) {
|
||||
return cdm.getClassForElement(node, new HashSet<Class>());
|
||||
return cdm.getClassForElement(node, new HashSet<Class<?>>());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -72,17 +72,17 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
*/
|
||||
private static class ClassDiscriminatorMapping {
|
||||
// The model class name.
|
||||
Class modelClass;
|
||||
Class<?> modelClass;
|
||||
// The name of the discriminator property.
|
||||
String discriminatorName;
|
||||
// The discriminator mappings for a model class.
|
||||
Map<String, Class> discriminatorMappings;
|
||||
Map<String, Class<?>> discriminatorMappings;
|
||||
|
||||
// Constructs a new class discriminator.
|
||||
ClassDiscriminatorMapping(Class cls, String propertyName, Map<String, Class> mappings) {
|
||||
ClassDiscriminatorMapping(Class<?> cls, String propertyName, Map<String, Class<?>> mappings) {
|
||||
modelClass = cls;
|
||||
discriminatorName = propertyName;
|
||||
discriminatorMappings = new HashMap<String, Class>();
|
||||
discriminatorMappings = new HashMap<String, Class<?>>();
|
||||
if (mappings != null) {
|
||||
discriminatorMappings.putAll(mappings);
|
||||
}
|
||||
@ -118,7 +118,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
* @param node The input data.
|
||||
* @param visitedClasses The set of classes that have already been visited.
|
||||
*/
|
||||
Class getClassForElement(JsonNode node, Set<Class> visitedClasses) {
|
||||
Class<?> getClassForElement(JsonNode node, Set<Class<?>> visitedClasses) {
|
||||
if (visitedClasses.contains(modelClass)) {
|
||||
// Class has already been visited.
|
||||
return null;
|
||||
@ -128,11 +128,11 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
if (discrValue == null) {
|
||||
return null;
|
||||
}
|
||||
Class cls = discriminatorMappings.get(discrValue);
|
||||
Class<?> cls = discriminatorMappings.get(discrValue);
|
||||
// It may not be sufficient to return this cls directly because that target class
|
||||
// may itself be a composed schema, possibly with its own discriminator.
|
||||
visitedClasses.add(modelClass);
|
||||
for (Class childClass : discriminatorMappings.values()) {
|
||||
for (Class<?> childClass : discriminatorMappings.values()) {
|
||||
ClassDiscriminatorMapping childCdm = modelDiscriminators.get(childClass);
|
||||
if (childCdm == null) {
|
||||
continue;
|
||||
@ -145,7 +145,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
}
|
||||
if (childCdm != null) {
|
||||
// Recursively traverse the discriminator mappings.
|
||||
Class childDiscr = childCdm.getClassForElement(node, visitedClasses);
|
||||
Class<?> childDiscr = childCdm.getClassForElement(node, visitedClasses);
|
||||
if (childDiscr != null) {
|
||||
return childDiscr;
|
||||
}
|
||||
@ -164,7 +164,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
* @param modelClass A OpenAPI model class.
|
||||
* @param inst The instance object.
|
||||
*/
|
||||
public static boolean isInstanceOf(Class modelClass, Object inst, Set<Class> visitedClasses) {
|
||||
public static boolean isInstanceOf(Class<?> modelClass, Object inst, Set<Class<?>> visitedClasses) {
|
||||
if (modelClass.isInstance(inst)) {
|
||||
// This handles the 'allOf' use case with single parent inheritance.
|
||||
return true;
|
||||
@ -191,12 +191,12 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
/**
|
||||
* A map of discriminators for all model classes.
|
||||
*/
|
||||
private static Map<Class, ClassDiscriminatorMapping> modelDiscriminators = new HashMap<Class, ClassDiscriminatorMapping>();
|
||||
private static Map<Class<?>, ClassDiscriminatorMapping> modelDiscriminators = new HashMap<Class<?>, ClassDiscriminatorMapping>();
|
||||
|
||||
/**
|
||||
* A map of oneOf/anyOf descendants for each model class.
|
||||
*/
|
||||
private static Map<Class, Map<String, GenericType>> modelDescendants = new HashMap<Class, Map<String, GenericType>>();
|
||||
private static Map<Class<?>, Map<String, GenericType>> modelDescendants = new HashMap<Class<?>, Map<String, GenericType>>();
|
||||
|
||||
/**
|
||||
* Register a model class discriminator.
|
||||
@ -205,7 +205,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
* @param discriminatorPropertyName the name of the discriminator property
|
||||
* @param mappings a map with the discriminator mappings.
|
||||
*/
|
||||
public static void registerDiscriminator(Class modelClass, String discriminatorPropertyName, Map<String, Class> mappings) {
|
||||
public static void registerDiscriminator(Class<?> modelClass, String discriminatorPropertyName, Map<String, Class<?>> mappings) {
|
||||
ClassDiscriminatorMapping m = new ClassDiscriminatorMapping(modelClass, discriminatorPropertyName, mappings);
|
||||
modelDiscriminators.put(modelClass, m);
|
||||
}
|
||||
@ -216,7 +216,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
* @param modelClass the model class
|
||||
* @param descendants a map of oneOf/anyOf descendants.
|
||||
*/
|
||||
public static void registerDescendants(Class modelClass, Map<String, GenericType> descendants) {
|
||||
public static void registerDescendants(Class<?> modelClass, Map<String, GenericType> descendants) {
|
||||
modelDescendants.put(modelClass, descendants);
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ public class Animal {
|
||||
|
||||
static {
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class> mappings = new HashMap<String, Class>();
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
mappings.put("BigCat", BigCat.class);
|
||||
mappings.put("Cat", Cat.class);
|
||||
mappings.put("Dog", Dog.class);
|
||||
|
@ -152,7 +152,7 @@ public class BigCat extends Cat {
|
||||
|
||||
static {
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class> mappings = new HashMap<String, Class>();
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
mappings.put("BigCat", BigCat.class);
|
||||
JSON.registerDiscriminator(BigCat.class, "className", mappings);
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ public class Cat extends Animal {
|
||||
|
||||
static {
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class> mappings = new HashMap<String, Class>();
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
mappings.put("BigCat", BigCat.class);
|
||||
mappings.put("Cat", Cat.class);
|
||||
JSON.registerDiscriminator(Cat.class, "className", mappings);
|
||||
|
@ -113,7 +113,7 @@ public class Dog extends Animal {
|
||||
|
||||
static {
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class> mappings = new HashMap<String, Class>();
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
mappings.put("Dog", Dog.class);
|
||||
JSON.registerDiscriminator(Dog.class, "className", mappings);
|
||||
}
|
||||
|
@ -3,7 +3,9 @@ package org.openapitools.client;
|
||||
import org.openapitools.client.model.Order;
|
||||
|
||||
import java.lang.Exception;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
@ -32,6 +34,33 @@ public class JSONTest {
|
||||
assertEquals(dateStr, dateFormat.format(o.getShipDate()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRFC3339DateFormatDate() throws Exception {
|
||||
{
|
||||
String dateStr = "2011-01-18 00:00:00.0Z";
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S'Z'");
|
||||
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
Date date = sdf.parse(dateStr);
|
||||
|
||||
RFC3339DateFormat df = new RFC3339DateFormat();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String s = df.format(date);
|
||||
System.out.println("DATE: " + s);
|
||||
assertEquals("2011-01-18T00:00:00.000Z", s);
|
||||
}
|
||||
{
|
||||
String dateStr = "2011-01-18 00:00:00.0";
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
|
||||
sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
|
||||
Date date = sdf.parse(dateStr);
|
||||
|
||||
RFC3339DateFormat df = new RFC3339DateFormat();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String s = df.format(date);
|
||||
assertEquals("2011-01-18T08:00:00.000Z", s);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomDate() throws Exception {
|
||||
final DateTimeFormatter dateFormat = DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.of("Etc/GMT+2"));
|
||||
|
@ -59,10 +59,10 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
* @param node The input data.
|
||||
* @param modelClass The class that contains the discriminator mappings.
|
||||
*/
|
||||
public static Class getClassForElement(JsonNode node, Class modelClass) {
|
||||
public static Class<?> getClassForElement(JsonNode node, Class<?> modelClass) {
|
||||
ClassDiscriminatorMapping cdm = modelDiscriminators.get(modelClass);
|
||||
if (cdm != null) {
|
||||
return cdm.getClassForElement(node, new HashSet<Class>());
|
||||
return cdm.getClassForElement(node, new HashSet<Class<?>>());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -72,17 +72,17 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
*/
|
||||
private static class ClassDiscriminatorMapping {
|
||||
// The model class name.
|
||||
Class modelClass;
|
||||
Class<?> modelClass;
|
||||
// The name of the discriminator property.
|
||||
String discriminatorName;
|
||||
// The discriminator mappings for a model class.
|
||||
Map<String, Class> discriminatorMappings;
|
||||
Map<String, Class<?>> discriminatorMappings;
|
||||
|
||||
// Constructs a new class discriminator.
|
||||
ClassDiscriminatorMapping(Class cls, String propertyName, Map<String, Class> mappings) {
|
||||
ClassDiscriminatorMapping(Class<?> cls, String propertyName, Map<String, Class<?>> mappings) {
|
||||
modelClass = cls;
|
||||
discriminatorName = propertyName;
|
||||
discriminatorMappings = new HashMap<String, Class>();
|
||||
discriminatorMappings = new HashMap<String, Class<?>>();
|
||||
if (mappings != null) {
|
||||
discriminatorMappings.putAll(mappings);
|
||||
}
|
||||
@ -118,7 +118,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
* @param node The input data.
|
||||
* @param visitedClasses The set of classes that have already been visited.
|
||||
*/
|
||||
Class getClassForElement(JsonNode node, Set<Class> visitedClasses) {
|
||||
Class<?> getClassForElement(JsonNode node, Set<Class<?>> visitedClasses) {
|
||||
if (visitedClasses.contains(modelClass)) {
|
||||
// Class has already been visited.
|
||||
return null;
|
||||
@ -128,11 +128,11 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
if (discrValue == null) {
|
||||
return null;
|
||||
}
|
||||
Class cls = discriminatorMappings.get(discrValue);
|
||||
Class<?> cls = discriminatorMappings.get(discrValue);
|
||||
// It may not be sufficient to return this cls directly because that target class
|
||||
// may itself be a composed schema, possibly with its own discriminator.
|
||||
visitedClasses.add(modelClass);
|
||||
for (Class childClass : discriminatorMappings.values()) {
|
||||
for (Class<?> childClass : discriminatorMappings.values()) {
|
||||
ClassDiscriminatorMapping childCdm = modelDiscriminators.get(childClass);
|
||||
if (childCdm == null) {
|
||||
continue;
|
||||
@ -145,7 +145,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
}
|
||||
if (childCdm != null) {
|
||||
// Recursively traverse the discriminator mappings.
|
||||
Class childDiscr = childCdm.getClassForElement(node, visitedClasses);
|
||||
Class<?> childDiscr = childCdm.getClassForElement(node, visitedClasses);
|
||||
if (childDiscr != null) {
|
||||
return childDiscr;
|
||||
}
|
||||
@ -164,7 +164,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
* @param modelClass A OpenAPI model class.
|
||||
* @param inst The instance object.
|
||||
*/
|
||||
public static boolean isInstanceOf(Class modelClass, Object inst, Set<Class> visitedClasses) {
|
||||
public static boolean isInstanceOf(Class<?> modelClass, Object inst, Set<Class<?>> visitedClasses) {
|
||||
if (modelClass.isInstance(inst)) {
|
||||
// This handles the 'allOf' use case with single parent inheritance.
|
||||
return true;
|
||||
@ -191,12 +191,12 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
/**
|
||||
* A map of discriminators for all model classes.
|
||||
*/
|
||||
private static Map<Class, ClassDiscriminatorMapping> modelDiscriminators = new HashMap<Class, ClassDiscriminatorMapping>();
|
||||
private static Map<Class<?>, ClassDiscriminatorMapping> modelDiscriminators = new HashMap<Class<?>, ClassDiscriminatorMapping>();
|
||||
|
||||
/**
|
||||
* A map of oneOf/anyOf descendants for each model class.
|
||||
*/
|
||||
private static Map<Class, Map<String, GenericType>> modelDescendants = new HashMap<Class, Map<String, GenericType>>();
|
||||
private static Map<Class<?>, Map<String, GenericType>> modelDescendants = new HashMap<Class<?>, Map<String, GenericType>>();
|
||||
|
||||
/**
|
||||
* Register a model class discriminator.
|
||||
@ -205,7 +205,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
* @param discriminatorPropertyName the name of the discriminator property
|
||||
* @param mappings a map with the discriminator mappings.
|
||||
*/
|
||||
public static void registerDiscriminator(Class modelClass, String discriminatorPropertyName, Map<String, Class> mappings) {
|
||||
public static void registerDiscriminator(Class<?> modelClass, String discriminatorPropertyName, Map<String, Class<?>> mappings) {
|
||||
ClassDiscriminatorMapping m = new ClassDiscriminatorMapping(modelClass, discriminatorPropertyName, mappings);
|
||||
modelDiscriminators.put(modelClass, m);
|
||||
}
|
||||
@ -216,7 +216,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
* @param modelClass the model class
|
||||
* @param descendants a map of oneOf/anyOf descendants.
|
||||
*/
|
||||
public static void registerDescendants(Class modelClass, Map<String, GenericType> descendants) {
|
||||
public static void registerDescendants(Class<?> modelClass, Map<String, GenericType> descendants) {
|
||||
modelDescendants.put(modelClass, descendants);
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ public class Animal {
|
||||
|
||||
static {
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class> mappings = new HashMap<String, Class>();
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
mappings.put("Cat", Cat.class);
|
||||
mappings.put("Dog", Dog.class);
|
||||
mappings.put("Animal", Animal.class);
|
||||
|
@ -113,7 +113,7 @@ public class Cat extends Animal {
|
||||
|
||||
static {
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class> mappings = new HashMap<String, Class>();
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
mappings.put("Cat", Cat.class);
|
||||
JSON.registerDiscriminator(Cat.class, "className", mappings);
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ public class ChildCat extends ParentPet {
|
||||
|
||||
static {
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class> mappings = new HashMap<String, Class>();
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
mappings.put("ChildCat", ChildCat.class);
|
||||
JSON.registerDiscriminator(ChildCat.class, "pet_type", mappings);
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ public class Dog extends Animal {
|
||||
|
||||
static {
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class> mappings = new HashMap<String, Class>();
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
mappings.put("Dog", Dog.class);
|
||||
JSON.registerDiscriminator(Dog.class, "className", mappings);
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ public class Fruit extends AbstractOpenApiSchema {
|
||||
*/
|
||||
@Override
|
||||
public Fruit getNullValue(DeserializationContext ctxt) throws JsonMappingException {
|
||||
throw new JsonMappingException("Fruit cannot be null");
|
||||
throw new JsonMappingException(ctxt.getParser(), "Fruit cannot be null");
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,12 +172,12 @@ public class Fruit extends AbstractOpenApiSchema {
|
||||
*/
|
||||
@Override
|
||||
public void setActualInstance(Object instance) {
|
||||
if (JSON.isInstanceOf(Apple.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf(Apple.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
||||
if (JSON.isInstanceOf(Banana.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf(Banana.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
@ -177,12 +177,12 @@ public class FruitReq extends AbstractOpenApiSchema {
|
||||
return;
|
||||
}
|
||||
|
||||
if (JSON.isInstanceOf(AppleReq.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf(AppleReq.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
||||
if (JSON.isInstanceOf(BananaReq.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf(BananaReq.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ public class GmFruit extends AbstractOpenApiSchema {
|
||||
*/
|
||||
@Override
|
||||
public GmFruit getNullValue(DeserializationContext ctxt) throws JsonMappingException {
|
||||
throw new JsonMappingException("GmFruit cannot be null");
|
||||
throw new JsonMappingException(ctxt.getParser(), "GmFruit cannot be null");
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,12 +155,12 @@ public class GmFruit extends AbstractOpenApiSchema {
|
||||
|
||||
@Override
|
||||
public void setActualInstance(Object instance) {
|
||||
if (JSON.isInstanceOf(Apple.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf(Apple.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
||||
if (JSON.isInstanceOf(Banana.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf(Banana.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ public class GrandparentAnimal {
|
||||
|
||||
static {
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class> mappings = new HashMap<String, Class>();
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
mappings.put("ChildCat", ChildCat.class);
|
||||
mappings.put("ParentPet", ParentPet.class);
|
||||
mappings.put("GrandparentAnimal", GrandparentAnimal.class);
|
||||
|
@ -164,7 +164,7 @@ public class Mammal extends AbstractOpenApiSchema {
|
||||
*/
|
||||
@Override
|
||||
public Mammal getNullValue(DeserializationContext ctxt) throws JsonMappingException {
|
||||
throw new JsonMappingException("Mammal cannot be null");
|
||||
throw new JsonMappingException(ctxt.getParser(), "Mammal cannot be null");
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,7 +199,7 @@ public class Mammal extends AbstractOpenApiSchema {
|
||||
});
|
||||
JSON.registerDescendants(Mammal.class, Collections.unmodifiableMap(schemas));
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class> mappings = new HashMap<String, Class>();
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
mappings.put("Pig", Pig.class);
|
||||
mappings.put("whale", Whale.class);
|
||||
mappings.put("zebra", Zebra.class);
|
||||
@ -221,17 +221,17 @@ public class Mammal extends AbstractOpenApiSchema {
|
||||
*/
|
||||
@Override
|
||||
public void setActualInstance(Object instance) {
|
||||
if (JSON.isInstanceOf(Pig.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf(Pig.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
||||
if (JSON.isInstanceOf(Whale.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf(Whale.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
||||
if (JSON.isInstanceOf(Zebra.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf(Zebra.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ public class NullableShape extends AbstractOpenApiSchema {
|
||||
});
|
||||
JSON.registerDescendants(NullableShape.class, Collections.unmodifiableMap(schemas));
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class> mappings = new HashMap<String, Class>();
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
mappings.put("Quadrilateral", Quadrilateral.class);
|
||||
mappings.put("Triangle", Triangle.class);
|
||||
mappings.put("NullableShape", NullableShape.class);
|
||||
@ -200,12 +200,12 @@ public class NullableShape extends AbstractOpenApiSchema {
|
||||
return;
|
||||
}
|
||||
|
||||
if (JSON.isInstanceOf(Quadrilateral.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf(Quadrilateral.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
||||
if (JSON.isInstanceOf(Triangle.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf(Triangle.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ public class ParentPet extends GrandparentAnimal {
|
||||
|
||||
static {
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class> mappings = new HashMap<String, Class>();
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
mappings.put("ChildCat", ChildCat.class);
|
||||
mappings.put("ParentPet", ParentPet.class);
|
||||
JSON.registerDiscriminator(ParentPet.class, "pet_type", mappings);
|
||||
|
@ -146,7 +146,7 @@ public class Pig extends AbstractOpenApiSchema {
|
||||
*/
|
||||
@Override
|
||||
public Pig getNullValue(DeserializationContext ctxt) throws JsonMappingException {
|
||||
throw new JsonMappingException("Pig cannot be null");
|
||||
throw new JsonMappingException(ctxt.getParser(), "Pig cannot be null");
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,7 +174,7 @@ public class Pig extends AbstractOpenApiSchema {
|
||||
});
|
||||
JSON.registerDescendants(Pig.class, Collections.unmodifiableMap(schemas));
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class> mappings = new HashMap<String, Class>();
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
mappings.put("BasquePig", BasquePig.class);
|
||||
mappings.put("DanishPig", DanishPig.class);
|
||||
mappings.put("Pig", Pig.class);
|
||||
@ -195,12 +195,12 @@ public class Pig extends AbstractOpenApiSchema {
|
||||
*/
|
||||
@Override
|
||||
public void setActualInstance(Object instance) {
|
||||
if (JSON.isInstanceOf(BasquePig.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf(BasquePig.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
||||
if (JSON.isInstanceOf(DanishPig.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf(DanishPig.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ public class Quadrilateral extends AbstractOpenApiSchema {
|
||||
*/
|
||||
@Override
|
||||
public Quadrilateral getNullValue(DeserializationContext ctxt) throws JsonMappingException {
|
||||
throw new JsonMappingException("Quadrilateral cannot be null");
|
||||
throw new JsonMappingException(ctxt.getParser(), "Quadrilateral cannot be null");
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,7 +174,7 @@ public class Quadrilateral extends AbstractOpenApiSchema {
|
||||
});
|
||||
JSON.registerDescendants(Quadrilateral.class, Collections.unmodifiableMap(schemas));
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class> mappings = new HashMap<String, Class>();
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
mappings.put("ComplexQuadrilateral", ComplexQuadrilateral.class);
|
||||
mappings.put("SimpleQuadrilateral", SimpleQuadrilateral.class);
|
||||
mappings.put("Quadrilateral", Quadrilateral.class);
|
||||
@ -195,12 +195,12 @@ public class Quadrilateral extends AbstractOpenApiSchema {
|
||||
*/
|
||||
@Override
|
||||
public void setActualInstance(Object instance) {
|
||||
if (JSON.isInstanceOf(ComplexQuadrilateral.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf(ComplexQuadrilateral.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
||||
if (JSON.isInstanceOf(SimpleQuadrilateral.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf(SimpleQuadrilateral.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ public class Shape extends AbstractOpenApiSchema {
|
||||
*/
|
||||
@Override
|
||||
public Shape getNullValue(DeserializationContext ctxt) throws JsonMappingException {
|
||||
throw new JsonMappingException("Shape cannot be null");
|
||||
throw new JsonMappingException(ctxt.getParser(), "Shape cannot be null");
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,7 +174,7 @@ public class Shape extends AbstractOpenApiSchema {
|
||||
});
|
||||
JSON.registerDescendants(Shape.class, Collections.unmodifiableMap(schemas));
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class> mappings = new HashMap<String, Class>();
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
mappings.put("Quadrilateral", Quadrilateral.class);
|
||||
mappings.put("Triangle", Triangle.class);
|
||||
mappings.put("Shape", Shape.class);
|
||||
@ -195,12 +195,12 @@ public class Shape extends AbstractOpenApiSchema {
|
||||
*/
|
||||
@Override
|
||||
public void setActualInstance(Object instance) {
|
||||
if (JSON.isInstanceOf(Quadrilateral.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf(Quadrilateral.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
||||
if (JSON.isInstanceOf(Triangle.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf(Triangle.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ public class ShapeOrNull extends AbstractOpenApiSchema {
|
||||
});
|
||||
JSON.registerDescendants(ShapeOrNull.class, Collections.unmodifiableMap(schemas));
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class> mappings = new HashMap<String, Class>();
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
mappings.put("Quadrilateral", Quadrilateral.class);
|
||||
mappings.put("Triangle", Triangle.class);
|
||||
mappings.put("ShapeOrNull", ShapeOrNull.class);
|
||||
@ -200,12 +200,12 @@ public class ShapeOrNull extends AbstractOpenApiSchema {
|
||||
return;
|
||||
}
|
||||
|
||||
if (JSON.isInstanceOf(Quadrilateral.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf(Quadrilateral.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
||||
if (JSON.isInstanceOf(Triangle.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf(Triangle.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ public class Triangle extends AbstractOpenApiSchema {
|
||||
*/
|
||||
@Override
|
||||
public Triangle getNullValue(DeserializationContext ctxt) throws JsonMappingException {
|
||||
throw new JsonMappingException("Triangle cannot be null");
|
||||
throw new JsonMappingException(ctxt.getParser(), "Triangle cannot be null");
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,7 +199,7 @@ public class Triangle extends AbstractOpenApiSchema {
|
||||
});
|
||||
JSON.registerDescendants(Triangle.class, Collections.unmodifiableMap(schemas));
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class> mappings = new HashMap<String, Class>();
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
mappings.put("EquilateralTriangle", EquilateralTriangle.class);
|
||||
mappings.put("IsoscelesTriangle", IsoscelesTriangle.class);
|
||||
mappings.put("ScaleneTriangle", ScaleneTriangle.class);
|
||||
@ -221,17 +221,17 @@ public class Triangle extends AbstractOpenApiSchema {
|
||||
*/
|
||||
@Override
|
||||
public void setActualInstance(Object instance) {
|
||||
if (JSON.isInstanceOf(EquilateralTriangle.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf(EquilateralTriangle.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
||||
if (JSON.isInstanceOf(IsoscelesTriangle.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf(IsoscelesTriangle.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
||||
if (JSON.isInstanceOf(ScaleneTriangle.class, instance, new HashSet<Class>())) {
|
||||
if (JSON.isInstanceOf(ScaleneTriangle.class, instance, new HashSet<Class<?>>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ public class JSONComposedSchemaTest {
|
||||
Exception exception = assertThrows(JsonMappingException.class, () -> {
|
||||
json.getContext(null).readValue(str, Shape.class);
|
||||
});
|
||||
assertEquals("Shape cannot be null", exception.getMessage());
|
||||
assertTrue(exception.getMessage().contains("Shape cannot be null"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -317,7 +317,7 @@ public class JSONComposedSchemaTest {
|
||||
Exception exception = assertThrows(JsonMappingException.class, () -> {
|
||||
GmFruit o = json.getContext(null).readValue(str, GmFruit.class);
|
||||
});
|
||||
assertEquals("GmFruit cannot be null", exception.getMessage());
|
||||
assertTrue(exception.getMessage().contains("GmFruit cannot be null"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,9 @@ package org.openapitools.client;
|
||||
import org.openapitools.client.model.Order;
|
||||
|
||||
import java.lang.Exception;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
@ -32,6 +34,33 @@ public class JSONTest {
|
||||
assertEquals(dateStr, dateFormat.format(o.getShipDate()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRFC3339DateFormatDate() throws Exception {
|
||||
{
|
||||
String dateStr = "2011-01-18 00:00:00.0Z";
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S'Z'");
|
||||
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
Date date = sdf.parse(dateStr);
|
||||
|
||||
RFC3339DateFormat df = new RFC3339DateFormat();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String s = df.format(date);
|
||||
System.out.println("DATE: " + s);
|
||||
assertEquals("2011-01-18T00:00:00.000Z", s);
|
||||
}
|
||||
{
|
||||
String dateStr = "2011-01-18 00:00:00.0";
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
|
||||
sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
|
||||
Date date = sdf.parse(dateStr);
|
||||
|
||||
RFC3339DateFormat df = new RFC3339DateFormat();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String s = df.format(date);
|
||||
assertEquals("2011-01-18T08:00:00.000Z", s);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomDate() throws Exception {
|
||||
final DateTimeFormatter dateFormat = DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.of("Etc/GMT+2"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user