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

tentative development for #38 #39

Merged
merged 20 commits into from
Aug 12, 2012
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
22 changes: 15 additions & 7 deletions src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.fasterxml.jackson.databind.introspect.ClassIntrospector;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import com.fasterxml.jackson.databind.introspect.VisibilityChecker;
import com.fasterxml.jackson.databind.jsonschema.JsonSchema;
import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor;
import com.fasterxml.jackson.databind.jsontype.*;
import com.fasterxml.jackson.databind.jsontype.impl.StdSubtypeResolver;
import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder;
Expand Down Expand Up @@ -2148,7 +2148,7 @@ public ObjectWriter writer(FilterProvider filterProvider) {
* pass specific schema object to {@link JsonGenerator} used for
* writing content.
*
* @param schema Schema to pass to generator
* @param schema JsonSchema to pass to generator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably an accidental change: schema here does NOT refer to JSON Schema (but rather to thing like what CSV module needs -- unfortunate overload for sure).

*/
public ObjectWriter writer(FormatSchema schema) {
return new ObjectWriter(this, getSerializationConfig(), schema);
Expand Down Expand Up @@ -2253,7 +2253,7 @@ public ObjectReader reader(JsonNodeFactory f)
* pass specific schema object to {@link JsonParser} used for
* reading content.
*
* @param schema Schema to pass to parser
* @param schema JsonSchema to pass to parser
*/
public ObjectReader reader(FormatSchema schema) {
return new ObjectReader(this, getDeserializationConfig(), null, null,
Expand Down Expand Up @@ -2386,7 +2386,7 @@ protected Object _convert(Object fromValue, JavaType toValueType)

/*
/**********************************************************
/* Extended Public API: JSON Schema generation
/* Extended Public API: JSON JsonSchema generation
/**********************************************************
*/

Expand All @@ -2395,10 +2395,18 @@ protected Object _convert(Object fromValue, JavaType toValueType)
* instance for specified class.
*
* @param t The class to generate schema for
* @return Constructed JSON schema.
*/
public JsonSchema generateJsonSchema(Class<?> t) throws JsonMappingException {
return _serializerProvider(getSerializationConfig()).generateJsonSchema(t);
public void acceptJsonFormatVisitor(Class<?> t, JsonFormatVisitor visitor) throws JsonMappingException {
if (t == null) {
throw new IllegalArgumentException("class must be provided");
}

if (visitor == null) {
return;
}
DefaultSerializerProvider provider = _serializerProvider(getSerializationConfig());
visitor.setProvider(provider);
provider.acceptJsonFormatVisitor(t, visitor);
}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.fasterxml.jackson.databind.ext;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -12,10 +11,12 @@

import com.fasterxml.jackson.core.*;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor;
import com.fasterxml.jackson.databind.ser.std.CalendarSerializer;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
Expand Down Expand Up @@ -62,9 +63,8 @@ public void serialize(XMLGregorianCalendar value, JsonGenerator jgen, Serializer
CalendarSerializer.instance.serialize(value.toGregorianCalendar(), jgen, provider);
}

@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException {
return CalendarSerializer.instance.getSchema(provider, typeHint);
public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) {
CalendarSerializer.instance.acceptJsonFormatVisitor(visitor, null);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.fasterxml.jackson.databind.ext;

import java.io.IOException;

import org.w3c.dom.Node;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSSerializer;

import com.fasterxml.jackson.core.*;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

public class DOMSerializer
Expand Down Expand Up @@ -39,9 +41,8 @@ public void serialize(Node value, JsonGenerator jgen, SerializerProvider provide
}

@Override
public JsonNode getSchema(SerializerProvider provider, java.lang.reflect.Type typeHint)
public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint)
{
// Well... it is serialized as String
return createSchemaNode("string", true);
visitor.anyFormat();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.fasterxml.jackson.databind.jsonschema;


import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor;

/**
* Marker interface for schema-aware serializers.
*/
public interface JsonFormatVisitorAware
{
/**
* Get the representation of the schema to which this serializer will conform.
* @param typeHint TODO
*
* @return <a href="http://json-schema.org/">Json-schema</a> for this serializer.
*/
public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint);
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.fasterxml.jackson.databind.jsonschema.factories;

import com.fasterxml.jackson.databind.jsonschema.types.AnySchema;
import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema;
import com.fasterxml.jackson.databind.jsonschema.visitors.JsonAnyFormatVisitor;

public class AnySchemaFactory extends SchemaFactory implements
JsonAnyFormatVisitor, SchemaFactoryDelegate {

protected SchemaFactory parent;
protected AnySchema anySchema;

public AnySchemaFactory(SchemaFactory parent) {
this.parent = parent;
setProvider(parent.getProvider());
anySchema = new AnySchema();
}

public JsonSchema getSchema() {
return anySchema;
}


}
Loading