Search in sources :

Example 1 with JsonObjectFormatVisitor

use of com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor in project torodb by torodb.

the class AbstractBackendSerializer method acceptJsonFormatVisitor.

@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType type) throws JsonMappingException {
    if (visitor == null) {
        return;
    }
    JsonObjectFormatVisitor v = visitor.expectObjectFormat(type);
    SerializerProvider prov = visitor.getProvider();
    final SerializationConfig config = prov.getConfig();
    BeanDescription beanDesc = config.introspect(type);
    JsonSubTypes jsonSubTypes;
    if (v != null) {
        for (BeanPropertyDefinition propDef : beanDesc.findProperties()) {
            if (propDef.isExplicitlyIncluded()) {
                jsonSubTypes = propDef.getPrimaryMember().getAnnotation(JsonSubTypes.class);
                if (jsonSubTypes != null) {
                    for (JsonSubTypes.Type jsonSubType : jsonSubTypes.value()) {
                        JavaType subType = TypeFactory.defaultInstance().constructType(jsonSubType.value());
                        depositSchemaProperty(v, jsonSubType.name(), subType);
                    }
                } else {
                    depositSchemaProperty(v, propDef.getName(), propDef.getPrimaryMember().getType(beanDesc.bindingsForBeanType()));
                }
            }
        }
    }
}
Also used : JsonSubTypes(com.fasterxml.jackson.annotation.JsonSubTypes) JavaType(com.fasterxml.jackson.databind.JavaType) JsonObjectFormatVisitor(com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor) SerializationConfig(com.fasterxml.jackson.databind.SerializationConfig) BeanDescription(com.fasterxml.jackson.databind.BeanDescription) BeanPropertyDefinition(com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition) SerializerProvider(com.fasterxml.jackson.databind.SerializerProvider)

Example 2 with JsonObjectFormatVisitor

use of com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor in project jackson-databind by FasterXML.

the class BeanSerializerBase method acceptJsonFormatVisitor.

@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException {
    //deposit your output format 
    if (visitor == null) {
        return;
    }
    JsonObjectFormatVisitor objectVisitor = visitor.expectObjectFormat(typeHint);
    if (objectVisitor == null) {
        return;
    }
    final SerializerProvider provider = visitor.getProvider();
    if (_propertyFilterId != null) {
        PropertyFilter filter = findPropertyFilter(visitor.getProvider(), _propertyFilterId, null);
        for (int i = 0, end = _props.length; i < end; ++i) {
            filter.depositSchemaProperty(_props[i], objectVisitor, provider);
        }
    } else {
        Class<?> view = ((_filteredProps == null) || (provider == null)) ? null : provider.getActiveView();
        final BeanPropertyWriter[] props;
        if (view != null) {
            props = _filteredProps;
        } else {
            props = _props;
        }
        for (int i = 0, end = props.length; i < end; ++i) {
            BeanPropertyWriter prop = props[i];
            if (prop != null) {
                // may be filtered out unconditionally
                prop.depositSchemaProperty(objectVisitor, provider);
            }
        }
    }
}
Also used : JsonObjectFormatVisitor(com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor)

Example 3 with JsonObjectFormatVisitor

use of com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor in project torodb by torodb.

the class AbstractBackendSerializer method depositSchemaProperty.

private void depositSchemaProperty(JsonObjectFormatVisitor v, String name, JavaType type) throws JsonMappingException {
    BeanProperty prop = new BeanProperty.Std(PropertyName.construct(name), type, null, null, null, PropertyMetadata.STD_OPTIONAL) {

        @Override
        public void depositSchemaProperty(JsonObjectFormatVisitor v) {
            try {
                if (v != null) {
                    if (isRequired()) {
                        v.property(this);
                    } else {
                        v.optionalProperty(this);
                    }
                }
            } catch (JsonMappingException jsonMappingException) {
                throw new RuntimeException(jsonMappingException);
            }
        }
    };
    prop.depositSchemaProperty(v);
}
Also used : JsonObjectFormatVisitor(com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) BeanProperty(com.fasterxml.jackson.databind.BeanProperty)

Aggregations

JsonObjectFormatVisitor (com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor)3 JsonSubTypes (com.fasterxml.jackson.annotation.JsonSubTypes)1 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)1 BeanProperty (com.fasterxml.jackson.databind.BeanProperty)1 JavaType (com.fasterxml.jackson.databind.JavaType)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 SerializationConfig (com.fasterxml.jackson.databind.SerializationConfig)1 SerializerProvider (com.fasterxml.jackson.databind.SerializerProvider)1 BeanPropertyDefinition (com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition)1