Java 类com.fasterxml.jackson.databind.jsonschema.SchemaAware 实例源码
项目:QuizUpWinner
文件:ObjectArraySerializer.java
public JsonNode getSchema(SerializerProvider paramSerializerProvider, Type paramType)
{
ObjectNode localObjectNode = createSchemaNode("array", true);
if (paramType != null)
{
JavaType localJavaType = paramSerializerProvider.constructType(paramType);
if (localJavaType.isArrayType())
{
Class localClass = ((ArrayType)localJavaType).getContentType().getRawClass();
if (localClass == Object.class)
{
localObjectNode.put("items", JsonSchema.getDefaultSchemaNode());
return localObjectNode;
}
JsonSerializer localJsonSerializer = paramSerializerProvider.findValueSerializer(localClass, this._property);
JsonNode localJsonNode;
if ((localJsonSerializer instanceof SchemaAware))
localJsonNode = ((SchemaAware)localJsonSerializer).getSchema(paramSerializerProvider, null);
else
localJsonNode = JsonSchema.getDefaultSchemaNode();
localObjectNode.put("items", localJsonNode);
}
}
return localObjectNode;
}
项目:QuizUpWinner
文件:EnumMapSerializer.java
public JsonNode getSchema(SerializerProvider paramSerializerProvider, Type paramType)
{
ObjectNode localObjectNode1 = createSchemaNode("object", true);
if ((paramType instanceof ParameterizedType))
{
Type[] arrayOfType = ((ParameterizedType)paramType).getActualTypeArguments();
if (arrayOfType.length == 2)
{
JavaType localJavaType1 = paramSerializerProvider.constructType(arrayOfType[0]);
JavaType localJavaType2 = paramSerializerProvider.constructType(arrayOfType[1]);
ObjectNode localObjectNode2 = JsonNodeFactory.instance.objectNode();
for (Enum localEnum : (Enum[])localJavaType1.getRawClass().getEnumConstants())
{
JsonSerializer localJsonSerializer = paramSerializerProvider.findValueSerializer(localJavaType2.getRawClass(), this._property);
JsonNode localJsonNode;
if ((localJsonSerializer instanceof SchemaAware))
localJsonNode = ((SchemaAware)localJsonSerializer).getSchema(paramSerializerProvider, null);
else
localJsonNode = JsonSchema.getDefaultSchemaNode();
localObjectNode2.put(paramSerializerProvider.getConfig().getAnnotationIntrospector().findEnumValue(localEnum), localJsonNode);
}
localObjectNode1.put("properties", localObjectNode2);
}
}
return localObjectNode1;
}
项目:joyplus-tv
文件:DefaultSerializerProvider.java
/**
* The method to be called by {@link ObjectMapper} and {@link ObjectWriter}
* to generate <a href="http://json-schema.org/">JSON schema</a> for
* given type.
*
* @param type The type for which to generate schema
*/
public JsonSchema generateJsonSchema(Class<?> type)
throws JsonMappingException
{
if (type == null) {
throw new IllegalArgumentException("A class must be provided");
}
/* no need for embedded type information for JSON schema generation (all
* type information it needs is accessible via "untyped" serializer)
*/
JsonSerializer<Object> ser = findValueSerializer(type, null);
JsonNode schemaNode = (ser instanceof SchemaAware) ?
((SchemaAware) ser).getSchema(this, null) :
JsonSchema.getDefaultSchemaNode();
if (!(schemaNode instanceof ObjectNode)) {
throw new IllegalArgumentException("Class " + type.getName() +
" would not be serialized as a JSON object and therefore has no schema");
}
return new JsonSchema((ObjectNode) schemaNode);
}
项目:joyplus-tv
文件:ObjectArraySerializer.java
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
throws JsonMappingException
{
ObjectNode o = createSchemaNode("array", true);
if (typeHint != null) {
JavaType javaType = provider.constructType(typeHint);
if (javaType.isArrayType()) {
Class<?> componentType = ((ArrayType) javaType).getContentType().getRawClass();
// 15-Oct-2010, tatu: We can't serialize plain Object.class; but what should it produce here? Untyped?
if (componentType == Object.class) {
o.put("items", JsonSchema.getDefaultSchemaNode());
} else {
JsonSerializer<Object> ser = provider.findValueSerializer(componentType, _property);
JsonNode schemaNode = (ser instanceof SchemaAware) ?
((SchemaAware) ser).getSchema(provider, null) :
JsonSchema.getDefaultSchemaNode();
o.put("items", schemaNode);
}
}
}
return o;
}
项目:joyplus-tv
文件:EnumMapSerializer.java
@SuppressWarnings("unchecked")
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
throws JsonMappingException
{
ObjectNode o = createSchemaNode("object", true);
if (typeHint instanceof ParameterizedType) {
Type[] typeArgs = ((ParameterizedType) typeHint).getActualTypeArguments();
if (typeArgs.length == 2) {
JavaType enumType = provider.constructType(typeArgs[0]);
JavaType valueType = provider.constructType(typeArgs[1]);
ObjectNode propsNode = JsonNodeFactory.instance.objectNode();
Class<Enum<?>> enumClass = (Class<Enum<?>>) enumType.getRawClass();
for (Enum<?> enumValue : enumClass.getEnumConstants()) {
JsonSerializer<Object> ser = provider.findValueSerializer(valueType.getRawClass(), _property);
JsonNode schemaNode = (ser instanceof SchemaAware) ?
((SchemaAware) ser).getSchema(provider, null) :
JsonSchema.getDefaultSchemaNode();
propsNode.put(provider.getConfig().getAnnotationIntrospector().findEnumValue((Enum<?>)enumValue), schemaNode);
}
o.put("properties", propsNode);
}
}
return o;
}
项目:joyplus-tv
文件:BeanPropertyWriter.java
/**
* Attempt to add the output of the given {@link BeanPropertyWriter} in the given {@link ObjectNode}.
* Otherwise, add the default schema {@link JsonNode} in place of the writer's output
*
* @param propertiesNode Node which the given property would exist within
* @param provider Provider that can be used for accessing dynamic aspects of serialization
* processing
*
* {@link BeanPropertyFilter#depositSchemaProperty(BeanPropertyWriter, ObjectNode, SerializerProvider)}
*
* @since 2.1
*/
public void depositSchemaProperty(ObjectNode propertiesNode, SerializerProvider provider)
throws JsonMappingException
{
JavaType propType = getSerializationType();
// 03-Dec-2010, tatu: SchemaAware REALLY should use JavaType, but alas it doesn't...
Type hint = (propType == null) ? getGenericPropertyType() : propType.getRawClass();
JsonNode schemaNode;
// Maybe it already has annotated/statically configured serializer?
JsonSerializer<Object> ser = getSerializer();
if (ser == null) { // nope
Class<?> serType = getRawSerializationType();
if (serType == null) {
serType = getPropertyType();
}
ser = provider.findValueSerializer(serType, this);
}
boolean isOptional = !isRequired(provider.getAnnotationIntrospector());
if (ser instanceof SchemaAware) {
schemaNode = ((SchemaAware) ser).getSchema(provider, hint, isOptional) ;
} else {
schemaNode = JsonSchema.getDefaultSchemaNode();
}
propertiesNode.put(getName(), schemaNode);
}
项目:sosoapi-base
文件:BeanPropertyWriter.java
/**
* Attempt to add the output of the given {@link BeanPropertyWriter} in the given {@link ObjectNode}.
* Otherwise, add the default schema {@link JsonNode} in place of the writer's output
*
* @param propertiesNode Node which the given property would exist within
* @param provider Provider that can be used for accessing dynamic aspects of serialization
* processing
*/
@Override
@Deprecated
public void depositSchemaProperty(ObjectNode propertiesNode, SerializerProvider provider)
throws JsonMappingException
{
JavaType propType = getSerializationType();
// 03-Dec-2010, tatu: SchemaAware REALLY should use JavaType, but alas it doesn't...
Type hint = (propType == null) ? getGenericPropertyType() : propType.getRawClass();
JsonNode schemaNode;
// Maybe it already has annotated/statically configured serializer?
JsonSerializer<Object> ser = getSerializer();
if (ser == null) { // nope
Class<?> serType = getRawSerializationType();
if (serType == null) {
serType = getPropertyType();
}
ser = provider.findValueSerializer(serType, this);
}
boolean isOptional = !isRequired();
if (ser instanceof SchemaAware) {
schemaNode = ((SchemaAware) ser).getSchema(provider, hint, isOptional) ;
} else {
schemaNode = com.fasterxml.jackson.databind.jsonschema.JsonSchema.getDefaultSchemaNode();
}
_depositSchemaProperty(propertiesNode, schemaNode);
}
项目:QuizUpWinner
文件:DefaultSerializerProvider.java
public JsonSchema generateJsonSchema(Class<?> paramClass)
{
if (paramClass == null)
throw new IllegalArgumentException("A class must be provided");
JsonSerializer localJsonSerializer = findValueSerializer(paramClass, null);
JsonNode localJsonNode1;
if ((localJsonSerializer instanceof SchemaAware))
localJsonNode1 = ((SchemaAware)localJsonSerializer).getSchema(this, null);
else
localJsonNode1 = JsonSchema.getDefaultSchemaNode();
JsonNode localJsonNode2 = localJsonNode1;
if (!(localJsonNode1 instanceof ObjectNode))
throw new IllegalArgumentException("Class " + paramClass.getName() + " would not be serialized as a JSON object and therefore has no schema");
return new JsonSchema((ObjectNode)localJsonNode2);
}
项目:QuizUpWinner
文件:AsArraySerializerBase.java
public JsonNode getSchema(SerializerProvider paramSerializerProvider, Type paramType)
{
ObjectNode localObjectNode = createSchemaNode("array", true);
Object localObject = null;
if (paramType != null)
{
JavaType localJavaType = paramSerializerProvider.constructType(paramType).getContentType();
localObject = localJavaType;
if ((localJavaType == null) && ((paramType instanceof ParameterizedType)))
{
Type[] arrayOfType = ((ParameterizedType)paramType).getActualTypeArguments();
if (arrayOfType.length == 1)
localObject = paramSerializerProvider.constructType(arrayOfType[0]);
}
}
if ((localObject == null) && (this._elementType != null))
localObject = this._elementType;
if (localObject != null)
{
Class localClass = ((JavaType)localObject).getRawClass();
JsonNode localJsonNode = null;
if (localClass != Object.class)
{
JsonSerializer localJsonSerializer = paramSerializerProvider.findValueSerializer((JavaType)localObject, this._property);
boolean bool = localJsonSerializer instanceof SchemaAware;
localJsonNode = null;
if (bool)
localJsonNode = ((SchemaAware)localJsonSerializer).getSchema(paramSerializerProvider, null);
}
if (localJsonNode == null)
localJsonNode = JsonSchema.getDefaultSchemaNode();
localObjectNode.put("items", localJsonNode);
}
return localObjectNode;
}
项目:QuizUpWinner
文件:BeanPropertyWriter.java
public void depositSchemaProperty(ObjectNode paramObjectNode, SerializerProvider paramSerializerProvider)
{
JavaType localJavaType = getSerializationType();
Object localObject;
if (localJavaType == null)
localObject = getGenericPropertyType();
else
localObject = localJavaType.getRawClass();
JsonSerializer localJsonSerializer1 = getSerializer();
JsonSerializer localJsonSerializer2 = localJsonSerializer1;
if (localJsonSerializer1 == null)
{
Class localClass1 = getRawSerializationType();
Class localClass2 = localClass1;
if (localClass1 == null)
localClass2 = getPropertyType();
localJsonSerializer2 = paramSerializerProvider.findValueSerializer(localClass2, this);
}
boolean bool;
if (!isRequired())
bool = true;
else
bool = false;
JsonNode localJsonNode;
if ((localJsonSerializer2 instanceof SchemaAware))
localJsonNode = ((SchemaAware)localJsonSerializer2).getSchema(paramSerializerProvider, (Type)localObject, bool);
else
localJsonNode = JsonSchema.getDefaultSchemaNode();
paramObjectNode.put(getName(), localJsonNode);
}
项目:joyplus-tv
文件:JsonValueSerializer.java
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
throws JsonMappingException
{
return (_valueSerializer instanceof SchemaAware) ?
((SchemaAware) _valueSerializer).getSchema(provider, null) :
JsonSchema.getDefaultSchemaNode();
}
项目:joyplus-tv
文件:StdDelegatingSerializer.java
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
throws JsonMappingException
{
if (_delegateSerializer instanceof SchemaAware) {
return ((SchemaAware) _delegateSerializer).getSchema(provider, typeHint);
}
return super.getSchema(provider, typeHint);
}
项目:joyplus-tv
文件:StdDelegatingSerializer.java
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint,
boolean isOptional) throws JsonMappingException
{
if (_delegateSerializer instanceof SchemaAware) {
return ((SchemaAware) _delegateSerializer).getSchema(provider, typeHint, isOptional);
}
return super.getSchema(provider, typeHint);
}
项目:jsonschema2pojo
文件:SchemaGenerator.java
private SchemaAware getValueSerializer(Object valueAsJavaType) throws JsonMappingException {
SerializerProvider serializerProvider = new DefaultSerializerProvider.Impl().createInstance(OBJECT_MAPPER.getSerializationConfig(), BeanSerializerFactory.instance);
if (valueAsJavaType == null) {
return NullSerializer.instance;
} else {
Class<? extends Object> javaTypeForValue = valueAsJavaType.getClass();
JsonSerializer<Object> valueSerializer = serializerProvider.findValueSerializer(javaTypeForValue, null);
return (SchemaAware) valueSerializer;
}
}
项目:QuizUpWinner
文件:JsonValueSerializer.java
public JsonNode getSchema(SerializerProvider paramSerializerProvider, Type paramType)
{
if ((this._valueSerializer instanceof SchemaAware))
return ((SchemaAware)this._valueSerializer).getSchema(paramSerializerProvider, null);
return JsonSchema.getDefaultSchemaNode();
}
项目:QuizUpWinner
文件:StdDelegatingSerializer.java
public JsonNode getSchema(SerializerProvider paramSerializerProvider, Type paramType)
{
if ((this._delegateSerializer instanceof SchemaAware))
return ((SchemaAware)this._delegateSerializer).getSchema(paramSerializerProvider, paramType);
return super.getSchema(paramSerializerProvider, paramType);
}
项目:QuizUpWinner
文件:StdDelegatingSerializer.java
public JsonNode getSchema(SerializerProvider paramSerializerProvider, Type paramType, boolean paramBoolean)
{
if ((this._delegateSerializer instanceof SchemaAware))
return ((SchemaAware)this._delegateSerializer).getSchema(paramSerializerProvider, paramType, paramBoolean);
return super.getSchema(paramSerializerProvider, paramType);
}
项目:joyplus-tv
文件:AsArraySerializerBase.java
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
throws JsonMappingException
{
/* 15-Jan-2010, tatu: This should probably be rewritten, given that
* more information about content type is actually being explicitly
* passed. So there should be less need to try to re-process that
* information.
*/
ObjectNode o = createSchemaNode("array", true);
JavaType contentType = null;
if (typeHint != null) {
JavaType javaType = provider.constructType(typeHint);
contentType = javaType.getContentType();
if (contentType == null) { // could still be parametrized (Iterators)
if (typeHint instanceof ParameterizedType) {
Type[] typeArgs = ((ParameterizedType) typeHint).getActualTypeArguments();
if (typeArgs.length == 1) {
contentType = provider.constructType(typeArgs[0]);
}
}
}
}
if (contentType == null && _elementType != null) {
contentType = _elementType;
}
if (contentType != null) {
JsonNode schemaNode = null;
// 15-Oct-2010, tatu: We can't serialize plain Object.class; but what should it produce here? Untyped?
if (contentType.getRawClass() != Object.class) {
JsonSerializer<Object> ser = provider.findValueSerializer(contentType, _property);
if (ser instanceof SchemaAware) {
schemaNode = ((SchemaAware) ser).getSchema(provider, null);
}
}
if (schemaNode == null) {
schemaNode = JsonSchema.getDefaultSchemaNode();
}
o.put("items", schemaNode);
}
return o;
}