List of usage examples for com.fasterxml.jackson.databind.introspect AnnotatedMember getRawType
public abstract Class<?> getRawType();
From source file:com.github.jonpeterson.jackson.module.versioning.VersionedModelUtils.java
public static BeanPropertyDefinition getSerializeToVersionProperty(BeanDescription beanDescription) throws RuntimeException { BeanPropertyDefinition serializeToVersionProperty = null; for (BeanPropertyDefinition definition : beanDescription.findProperties()) { // merge field and accessor annotations if (definition instanceof POJOPropertyBuilder) ((POJOPropertyBuilder) definition).mergeAnnotations(true); AnnotatedMember accessor = definition.getAccessor(); if (accessor != null && accessor.hasAnnotation(JsonSerializeToVersion.class)) { if (serializeToVersionProperty != null) throw new RuntimeException("@" + JsonSerializeToVersion.class.getSimpleName() + " must be present on at most one field or method"); if (accessor.getRawType() != String.class || (definition.getField() == null && !definition.hasGetter())) throw new RuntimeException("@" + JsonSerializeToVersion.class.getSimpleName() + " must be on a field or a getter method that returns a String"); serializeToVersionProperty = definition; }/* w ww .ja v a 2s . c o m*/ } return serializeToVersionProperty; }
From source file:org.jongo.marshall.jackson.JacksonObjectIdUpdater.java
public void setObjectId(Object target, ObjectId id) { for (BeanPropertyDefinition def : beanDescription(target.getClass()).findProperties()) { if (isIdProperty(def)) { AnnotatedMember accessor = def.getAccessor(); accessor.fixAccess();/*w w w . j ava2s. c o m*/ if (accessor.getValue(target) != null) { throw new IllegalArgumentException("Unable to set objectid on class: " + target.getClass()); } AnnotatedMember field = def.getField(); field.fixAccess(); Class<?> type = field.getRawType(); if (ObjectId.class.isAssignableFrom(type)) { field.setValue(target, id); } else if (type.equals(String.class) && isObjectId(def)) { field.setValue(target, id.toString()); } return; } } }
From source file:org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaConverter.java
private List<AbstractJsonSchemaProperty<?>> getPropertiesFor(Class<?> type, final ResourceMetadata metadata, final Definitions definitions) { final PersistentEntity<?, ?> entity = entities.getPersistentEntity(type); final JacksonMetadata jackson = new JacksonMetadata(objectMapper, type); if (entity == null) { return Collections.<AbstractJsonSchemaProperty<?>>emptyList(); }//from w w w . j av a 2s . c om JsonSchemaPropertyRegistrar registrar = new JsonSchemaPropertyRegistrar(jackson); for (BeanPropertyDefinition definition : jackson) { PersistentProperty<?> persistentProperty = entity.getPersistentProperty(definition.getInternalName()); // First pass, early drops to avoid unnecessary calculation if (persistentProperty != null) { if (persistentProperty.isIdProperty() && !configuration.isIdExposedFor(type)) { continue; } if (persistentProperty.isVersionProperty()) { continue; } if (!definition.couldSerialize()) { continue; } } AnnotatedMember primaryMember = definition.getPrimaryMember(); if (primaryMember == null) { continue; } TypeInformation<?> propertyType = persistentProperty == null ? ClassTypeInformation.from(primaryMember.getRawType()) : persistentProperty.getTypeInformation(); TypeInformation<?> actualPropertyType = propertyType.getActualType(); Class<?> rawPropertyType = propertyType.getType(); JsonSchemaFormat format = configuration.getMetadataConfiguration().getSchemaFormatFor(rawPropertyType); ResourceDescription description = persistentProperty == null ? jackson.getFallbackDescription(metadata, definition) : getDescriptionFor(persistentProperty, metadata); JsonSchemaProperty property = getSchemaProperty(definition, propertyType, description); boolean isSyntheticProperty = persistentProperty == null; boolean isNotWritable = !isSyntheticProperty && !persistentProperty.isWritable(); boolean isJacksonReadOnly = !isSyntheticProperty && jackson.isReadOnly(persistentProperty); if (isSyntheticProperty || isNotWritable || isJacksonReadOnly) { property = property.withReadOnly(); } if (format != null) { // Types with explicitly registered format -> value object with format registrar.register(property.withFormat(format), actualPropertyType); continue; } Pattern pattern = configuration.getMetadataConfiguration().getPatternFor(rawPropertyType); if (pattern != null) { registrar.register(property.withPattern(pattern), actualPropertyType); continue; } if (jackson.isValueType()) { registrar.register(property.with(STRING_TYPE_INFORMATION), actualPropertyType); continue; } if (persistentProperty == null) { registrar.register(property, actualPropertyType); continue; } if (configuration.isLookupType(persistentProperty.getActualType())) { registrar.register(property.with(propertyType), actualPropertyType); } else if (associations.isLinkableAssociation(persistentProperty)) { registrar.register(property.asAssociation(), null); } else { if (persistentProperty.isEntity()) { if (!definitions.hasDefinitionFor(propertyType)) { definitions.addDefinition(propertyType, new Item(propertyType, getNestedPropertiesFor(persistentProperty, definitions))); } registrar.register(property.with(propertyType, Definitions.getReference(propertyType)), actualPropertyType); } else { registrar.register(property.with(propertyType), actualPropertyType); } } } return registrar.getProperties(); }