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 all 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
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ com.fasterxml.jackson.databind.exc,
com.fasterxml.jackson.databind.ext,
com.fasterxml.jackson.databind.introspect,
com.fasterxml.jackson.databind.jsonschema,
com.fasterxml.jackson.databind.jsonschema.factories,
com.fasterxml.jackson.databind.jsonschema.types,
com.fasterxml.jackson.databind.jsonFormatVisitors,
com.fasterxml.jackson.databind.jsontype,
com.fasterxml.jackson.databind.jsontype.impl,
com.fasterxml.jackson.databind.module,
Expand Down
24 changes: 18 additions & 6 deletions src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.deser.*;
import com.fasterxml.jackson.databind.introspect.BasicClassIntrospector;
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.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.jsonschema.JsonSchema;
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 @@ -2321,7 +2325,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 @@ -2454,7 +2458,7 @@ protected Object _convert(Object fromValue, JavaType toValueType)

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

Expand All @@ -2463,10 +2467,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, JsonFormatVisitorWrapper 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.jsonFormatVisitors.JsonFormatVisitorWrapper;
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(JsonFormatVisitorWrapper 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.jsonFormatVisitors.JsonFormatVisitorWrapper;
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(JsonFormatVisitorWrapper visitor, JavaType typeHint)
{
// Well... it is serialized as String
return createSchemaNode("string", true);
visitor.expectAnyFormat(typeHint);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.fasterxml.jackson.databind.jsonFormatVisitors;

public interface JsonAnyFormatVisitor {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.fasterxml.jackson.databind.jsonFormatVisitors;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.jsonschema.types.SchemaType;

public interface JsonArrayFormatVisitor extends JsonFormatVisitorWithSerializerProvider {

void itemsFormat(JavaType contentType);

void itemsFormat(SchemaType format);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.fasterxml.jackson.databind.jsonFormatVisitors;

public interface JsonBooleanFormatVisitor extends JsonValueFormatVisitor {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.fasterxml.jackson.databind.jsonFormatVisitors;


import com.fasterxml.jackson.databind.JavaType;

/**
* 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(JsonFormatVisitorWrapper visitor, JavaType typeHint);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
*
*/
package com.fasterxml.jackson.databind.jsonFormatVisitors;

import com.fasterxml.jackson.databind.SerializerProvider;

/**
* @author jphelan
*
*/
public interface JsonFormatVisitorWithSerializerProvider {

public SerializerProvider getProvider();
public abstract void setProvider(SerializerProvider provider);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.fasterxml.jackson.databind.jsonFormatVisitors;

import com.fasterxml.jackson.databind.JavaType;

public interface JsonFormatVisitorWrapper extends JsonFormatVisitorWithSerializerProvider{

public JsonObjectFormatVisitor expectObjectFormat(JavaType convertedType);
public JsonArrayFormatVisitor expectArrayFormat(JavaType convertedType);
public JsonStringFormatVisitor expectStringFormat(JavaType convertedType);
public JsonNumberFormatVisitor expectNumberFormat(JavaType convertedType);
public JsonIntegerFormatVisitor expectIntegerFormat(JavaType convertedType);
public JsonBooleanFormatVisitor expectBooleanFormat(JavaType convertedType);
public JsonNullFormatVisitor expectNullFormat(JavaType convertedType);
public JsonAnyFormatVisitor expectAnyFormat(JavaType convertedType);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.fasterxml.jackson.databind.jsonFormatVisitors;

public interface JsonIntegerFormatVisitor extends JsonValueFormatVisitor {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.fasterxml.jackson.databind.jsonFormatVisitors;

public interface JsonNullFormatVisitor {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.fasterxml.jackson.databind.jsonFormatVisitors;


public interface JsonNumberFormatVisitor extends JsonValueFormatVisitor{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.fasterxml.jackson.databind.jsonFormatVisitors;


import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;

public interface JsonObjectFormatVisitor extends JsonFormatVisitorWithSerializerProvider {

public void property(BeanPropertyWriter writer);

public void optionalProperty(BeanPropertyWriter writer);

public void property(String name, JsonFormatVisitorAware handler, JavaType propertyTypeHint);

public void optionalProperty(String name, JsonFormatVisitorAware handler,
JavaType propertyTypeHint);

public void property(String name);

public void optionalProperty(String name);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.fasterxml.jackson.databind.jsonFormatVisitors;

public interface JsonStringFormatVisitor extends JsonValueFormatVisitor {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.fasterxml.jackson.databind.jsonFormatVisitors;

import java.util.Set;

import com.fasterxml.jackson.databind.jsonschema.types.JsonValueFormat;

public interface JsonValueFormatVisitor {

void format(JsonValueFormat format);

void enumTypes(Set<String> enums);
}

This file was deleted.

Loading