Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialize empty JSON schemas #110

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
* @author jphelan
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonTypeInfo(use = Id.CUSTOM, include = As.PROPERTY, property = "type")
@JsonTypeInfo(use = Id.CUSTOM, include = As.PROPERTY, property = "type", defaultImpl = AnySchema.class)
@JsonTypeIdResolver(JsonSchemaIdResolver.class)
public abstract class JsonSchema
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.fasterxml.jackson.module.jsonSchema;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes;
import com.fasterxml.jackson.module.jsonSchema.types.ArraySchema;

public class NoTypeSchemaReadTest extends SchemaTestBase {
public void testNoTypeSchema() throws Exception {
String input = "{}";

ObjectMapper mapper = new ObjectMapper();
JsonSchema schema = mapper.readValue(input, JsonSchema.class);

assertEquals(JsonFormatTypes.ANY, schema.getType());
}

public void testNoTypeSingleItems() throws Exception {
String input = "{ \"type\": \"array\", \"items\": {} }";

ObjectMapper mapper = new ObjectMapper();
JsonSchema schema = mapper.readValue(input, JsonSchema.class);

assertTrue(schema instanceof ArraySchema);

ArraySchema.Items items = ((ArraySchema) schema).getItems();
assertNotNull(items);
assertTrue(items.isSingleItems());

JsonSchema itemsSchema = items.asSingleItems().getSchema();
assertNotNull(itemsSchema);
assertEquals(JsonFormatTypes.ANY, itemsSchema.getType());
}

public void testNoTypeArrayItems() throws Exception {
String input = "{ \"type\": \"array\", \"items\": [{}] }";

ObjectMapper mapper = new ObjectMapper();
JsonSchema schema = mapper.readValue(input, JsonSchema.class);

assertTrue(schema instanceof ArraySchema);

ArraySchema.Items items = ((ArraySchema) schema).getItems();
assertNotNull(items);
assertTrue(items.isArrayItems());

JsonSchema[] itemsSchemas = items.asArrayItems().getJsonSchemas();
assertNotNull(itemsSchemas);
assertEquals(itemsSchemas.length, 1);
assertNotNull(itemsSchemas[0]);
assertEquals(JsonFormatTypes.ANY, itemsSchemas[0].getType());
}
}