use of com.fasterxml.jackson.databind.BeanDescription in project jackson-databind by FasterXML.
the class TypeNameIdResolver method idFromClass.
protected String idFromClass(Class<?> clazz) {
if (clazz == null) {
return null;
}
Class<?> cls = _typeFactory.constructType(clazz).getRawClass();
final String key = cls.getName();
String name;
synchronized (_typeToId) {
name = _typeToId.get(key);
if (name == null) {
// can either throw an exception, or use default name...
if (_config.isAnnotationProcessingEnabled()) {
BeanDescription beanDesc = _config.introspectClassAnnotations(cls);
name = _config.getAnnotationIntrospector().findTypeName(beanDesc.getClassInfo());
}
if (name == null) {
// And if still not found, let's choose default?
name = _defaultTypeId(cls);
}
_typeToId.put(key, name);
}
}
return name;
}
use of com.fasterxml.jackson.databind.BeanDescription 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()));
}
}
}
}
}
use of com.fasterxml.jackson.databind.BeanDescription in project swagger-core by swagger-api.
the class DefaultParameterExtension method handleAdditionalAnnotation.
/**
* Adds additional annotation processing support
*
* @param parameters
* @param annotation
* @param type
* @param typesToSkip
*/
private void handleAdditionalAnnotation(List<Parameter> parameters, Annotation annotation, final Type type, Set<Type> typesToSkip) {
if (CLASS_BEAN_PARAM != null && CLASS_BEAN_PARAM.isAssignableFrom(annotation.getClass())) {
// Use Jackson's logic for processing Beans
final BeanDescription beanDesc = mapper.getSerializationConfig().introspect(constructType(type));
final List<BeanPropertyDefinition> properties = beanDesc.findProperties();
for (final BeanPropertyDefinition propDef : properties) {
final AnnotatedField field = propDef.getField();
final AnnotatedMethod setter = propDef.getSetter();
final AnnotatedMethod getter = propDef.getGetter();
final List<Annotation> paramAnnotations = new ArrayList<Annotation>();
final Iterator<SwaggerExtension> extensions = SwaggerExtensions.chain();
Type paramType = null;
// Gather the field's details
if (field != null) {
paramType = field.getRawType();
for (final Annotation fieldAnnotation : field.annotations()) {
if (!paramAnnotations.contains(fieldAnnotation)) {
paramAnnotations.add(fieldAnnotation);
}
}
}
// Gather the setter's details but only the ones we need
if (setter != null) {
// Do not set the param class/type from the setter if the values are already identified
if (paramType == null) {
paramType = setter.getRawParameterTypes() != null ? setter.getRawParameterTypes()[0] : null;
}
for (final Annotation fieldAnnotation : setter.annotations()) {
if (!paramAnnotations.contains(fieldAnnotation)) {
paramAnnotations.add(fieldAnnotation);
}
}
}
// Gather the getter's details but only the ones we need
if (getter != null) {
// Do not set the param class/type from the getter if the values are already identified
if (paramType == null) {
paramType = getter.getRawReturnType();
}
for (final Annotation fieldAnnotation : getter.annotations()) {
if (!paramAnnotations.contains(fieldAnnotation)) {
paramAnnotations.add(fieldAnnotation);
}
}
}
if (paramType == null) {
continue;
}
// Re-process all Bean fields and let the default swagger-jaxrs/swagger-jersey-jaxrs processors do their thing
List<Parameter> extracted = extensions.next().extractParameters(paramAnnotations, paramType, typesToSkip, extensions);
// since downstream processors won't know how to introspect @BeanParam, process here
for (Parameter param : extracted) {
if (ParameterProcessor.applyAnnotations(null, param, paramType, paramAnnotations) != null) {
parameters.add(param);
}
}
}
}
}
use of com.fasterxml.jackson.databind.BeanDescription in project Gaffer by gchq.
the class GraphConfigurationService method getSerialisedFields.
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Need to wrap all runtime exceptions before they are given to the user")
@Override
public Set<String> getSerialisedFields(final String className) {
final Class<?> clazz;
try {
clazz = Class.forName(className);
} catch (final Exception e) {
throw new IllegalArgumentException("Class name was not recognised: " + className, e);
}
final ObjectMapper mapper = new ObjectMapper();
final JavaType type = mapper.getTypeFactory().constructType(clazz);
final BeanDescription introspection = mapper.getSerializationConfig().introspect(type);
final List<BeanPropertyDefinition> properties = introspection.findProperties();
final Set<String> fields = new HashSet<>();
for (final BeanPropertyDefinition property : properties) {
fields.add(property.getName());
}
return fields;
}
use of com.fasterxml.jackson.databind.BeanDescription in project autorest-clientruntime-for-java by Azure.
the class FlatteningDeserializer method getModule.
/**
* Gets a module wrapping this serializer as an adapter for the Jackson
* ObjectMapper.
*
* @param mapper the object mapper for default deserializations
* @return a simple module to be plugged onto Jackson ObjectMapper.
*/
public static SimpleModule getModule(final ObjectMapper mapper) {
SimpleModule module = new SimpleModule();
module.setDeserializerModifier(new BeanDeserializerModifier() {
@Override
public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) {
if (beanDesc.getBeanClass().getAnnotation(JsonFlatten.class) != null) {
return new FlatteningDeserializer(beanDesc.getBeanClass(), deserializer, mapper);
}
return deserializer;
}
});
return module;
}
Aggregations