@Nullable private TypeToken<?> getPropertyType(TypeToken<?> beanType, Method readMethod, Method writeMethod, AnnotatedField field, ApiConfig config) { if (readMethod != null) { // read method's return type is the property type return ApiAnnotationIntrospector.getSchemaType( beanType.resolveType(readMethod.getGenericReturnType()), config); } else if (writeMethod != null) { Type[] paramTypes = writeMethod.getGenericParameterTypes(); if (paramTypes.length == 1) { // write method's first parameter type is the property type return ApiAnnotationIntrospector.getSchemaType( beanType.resolveType(paramTypes[0]), config); } } else if (field != null) { return ApiAnnotationIntrospector.getSchemaType( beanType.resolveType(field.getGenericType()), config); } return null; }
@Override public PropertyName findNameForSerialization(Annotated a) { if (!(a instanceof AnnotatedField) && !(a instanceof AnnotatedMethod)) { return super.findNameForSerialization(a); } IndexableProperty property = a.getAnnotation(IndexableProperty.class); if (property != null && !property.name().isEmpty()) { return new PropertyName(property.name()); } IndexableComponent component = a.getAnnotation(IndexableComponent.class); if (component != null && !component.name().isEmpty()) { return new PropertyName(component.name()); } IndexableProperties properties = a.getAnnotation(IndexableProperties.class); if (properties != null && !properties.name().isEmpty()) { return new PropertyName(properties.name()); } return PropertyName.USE_DEFAULT; }
@Override public PropertyName findNameForDeserialization(Annotated a) { if (!(a instanceof AnnotatedField) && !(a instanceof AnnotatedMethod)) { return super.findNameForDeserialization(a); } IndexableProperty property = a.getAnnotation(IndexableProperty.class); if (property != null && !property.name().isEmpty()) { return new PropertyName(property.name()); } IndexableComponent component = a.getAnnotation(IndexableComponent.class); if (component != null && !component.name().isEmpty()) { return new PropertyName(component.name()); } IndexableProperties properties = a.getAnnotation(IndexableProperties.class); if (properties != null && !properties.name().isEmpty()) { return new PropertyName(properties.name()); } return PropertyName.USE_DEFAULT; }
protected SettableBeanProperty constructSettableProperty(DeserializationContext paramDeserializationContext, BeanDescription paramBeanDescription, BeanPropertyDefinition paramBeanPropertyDefinition, Type paramType) { AnnotatedMember localAnnotatedMember = paramBeanPropertyDefinition.getMutator(); if (paramDeserializationContext.canOverrideAccessModifiers()) localAnnotatedMember.fixAccess(); JavaType localJavaType1 = paramBeanDescription.resolveType(paramType); BeanProperty.Std localStd = new BeanProperty.Std(paramBeanPropertyDefinition.getName(), localJavaType1, paramBeanPropertyDefinition.getWrapperName(), paramBeanDescription.getClassAnnotations(), localAnnotatedMember, paramBeanPropertyDefinition.isRequired()); JavaType localJavaType2 = resolveType(paramDeserializationContext, paramBeanDescription, localJavaType1, localAnnotatedMember); if (localJavaType2 != localJavaType1) localStd.withType(localJavaType2); JsonDeserializer localJsonDeserializer = findDeserializerFromAnnotation(paramDeserializationContext, localAnnotatedMember); JavaType localJavaType3 = modifyTypeByAnnotation(paramDeserializationContext, localAnnotatedMember, localJavaType2); TypeDeserializer localTypeDeserializer = (TypeDeserializer)localJavaType3.getTypeHandler(); Object localObject; if ((localAnnotatedMember instanceof AnnotatedMethod)) localObject = new MethodProperty(paramBeanPropertyDefinition, localJavaType3, localTypeDeserializer, paramBeanDescription.getClassAnnotations(), (AnnotatedMethod)localAnnotatedMember); else localObject = new FieldProperty(paramBeanPropertyDefinition, localJavaType3, localTypeDeserializer, paramBeanDescription.getClassAnnotations(), (AnnotatedField)localAnnotatedMember); if (localJsonDeserializer != null) localObject = ((SettableBeanProperty)localObject).withValueDeserializer(localJsonDeserializer); AnnotationIntrospector.ReferenceProperty localReferenceProperty = paramBeanPropertyDefinition.findReferenceType(); if ((localReferenceProperty != null) && (localReferenceProperty.isManagedReference())) ((SettableBeanProperty)localObject).setManagedReferenceName(localReferenceProperty.getName()); return localObject; }
public PropertyName findNameForDeserialization(Annotated paramAnnotated) { String str; if ((paramAnnotated instanceof AnnotatedField)) str = findDeserializationName((AnnotatedField)paramAnnotated); else if ((paramAnnotated instanceof AnnotatedMethod)) str = findDeserializationName((AnnotatedMethod)paramAnnotated); else if ((paramAnnotated instanceof AnnotatedParameter)) str = findDeserializationName((AnnotatedParameter)paramAnnotated); else str = null; if (str != null) { if (str.length() == 0) return PropertyName.USE_DEFAULT; return new PropertyName(str); } return null; }
public PropertyName findNameForSerialization(Annotated paramAnnotated) { String str; if ((paramAnnotated instanceof AnnotatedField)) str = findSerializationName((AnnotatedField)paramAnnotated); else if ((paramAnnotated instanceof AnnotatedMethod)) str = findSerializationName((AnnotatedMethod)paramAnnotated); else str = null; if (str != null) { if (str.length() == 0) return PropertyName.USE_DEFAULT; return new PropertyName(str); } return null; }
private <T> void verifyClazzIsConfigurable(Class<T> clazz) { final List<BeanPropertyDefinition> beanDefs = jsonMapper.getSerializationConfig() .introspect(jsonMapper.constructType(clazz)) .findProperties(); for (BeanPropertyDefinition beanDef : beanDefs) { final AnnotatedField field = beanDef.getField(); if (field == null || !field.hasAnnotation(JsonProperty.class)) { throw new ProvisionException( String.format( "JsonConfigurator requires Jackson-annotated Config objects to have field annotations. %s doesn't", clazz ) ); } } }
public static AnnotatedField build(final AnnotatedClass annotatedClass, final Field field, final AnnotationMap annotationMap) { final Constructor<?> constructor = AnnotatedField.class.getConstructors()[0]; return ExceptionUtil.wrapCatchedExceptions(new Callable<AnnotatedField>() { @Override public AnnotatedField call() throws Exception { return buildAnnotatedField(annotatedClass, field, annotationMap, constructor); } }, "Exception while building AnnotatedField"); }
private static AnnotatedField buildAnnotatedField(AnnotatedClass annotatedClass, Field field, AnnotationMap annotationMap, Constructor<?> constructor) throws IllegalAccessException, InstantiationException, InvocationTargetException { Class<?> firstParameterType = constructor.getParameterTypes()[0]; PreconditionUtil.assertTrue(CANNOT_FIND_PROPER_CONSTRUCTOR, firstParameterType == AnnotatedClass.class || TypeResolutionContext.class.equals(firstParameterType)); return (AnnotatedField) constructor.newInstance(annotatedClass, field, annotationMap); }
protected Optional<String> getName(Field field) { ObjectMapper objectMapper = context.getObjectMapper(); SerializationConfig serializationConfig = objectMapper.getSerializationConfig(); if (serializationConfig != null && serializationConfig.getPropertyNamingStrategy() != null) { AnnotationMap annotationMap = buildAnnotationMap(field.getDeclaredAnnotations()); AnnotatedClass annotatedClass = AnnotatedClassBuilder.build(field.getDeclaringClass(), serializationConfig); AnnotatedField annotatedField = AnnotatedFieldBuilder.build(annotatedClass, field, annotationMap); return Optional.of(serializationConfig.getPropertyNamingStrategy().nameForField(serializationConfig, annotatedField, field.getName())); } return Optional.empty(); }
@Override public String nameForField(MapperConfig<?> config, AnnotatedField field, String defaultName) { if (field.getDeclaringClass() == this.effectiveType) { return fieldToJsonMapping .getOrDefault(defaultName, super.nameForField(config, field, defaultName)); } else { return super.nameForField(config, field, defaultName); } }
public String getName(Field field) { String name = field.getName(); if (field.isAnnotationPresent(JsonProperty.class) && !"".equals(field.getAnnotation(JsonProperty.class).value())) { name = field.getAnnotation(JsonProperty.class).value(); } else if (serializationConfig != null && serializationConfig.getPropertyNamingStrategy() != null) { AnnotationMap annotationMap = buildAnnotationMap(field.getDeclaredAnnotations()); AnnotatedClass annotatedClass = AnnotatedClassBuilder.build(field.getDeclaringClass(), serializationConfig); AnnotatedField annotatedField = AnnotatedFieldBuilder.build(annotatedClass, field, annotationMap); name = serializationConfig.getPropertyNamingStrategy().nameForField(serializationConfig, annotatedField, name); } return name; }
public static AnnotatedField build(AnnotatedClass annotatedClass, Field field, AnnotationMap annotationMap) { for(Constructor<?> constructor : AnnotatedField.class.getConstructors()) { try { return buildAnnotatedField(annotatedClass, field, annotationMap, constructor); } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) { throw new InternalException("Exception while building " + AnnotatedField.class.getCanonicalName(), e); } } throw new InternalException(CANNOT_FIND_PROPER_CONSTRUCTOR); }
private static AnnotatedField buildAnnotatedField(AnnotatedClass annotatedClass, Field field, AnnotationMap annotationMap, Constructor<?> constructor) throws IllegalAccessException, InstantiationException, InvocationTargetException { Class<?> firstParameterType = constructor.getParameterTypes()[0]; if (firstParameterType == AnnotatedClass.class || "TypeResolutionContext".equals(firstParameterType.getSimpleName())) { return (AnnotatedField) constructor.newInstance(annotatedClass, field, annotationMap); } else { throw new InternalException(CANNOT_FIND_PROPER_CONSTRUCTOR); } }
@Override public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException { if (property != null) { Annotated annotated = property.getMember(); if (annotated instanceof AnnotatedField || annotated instanceof AnnotatedMethod) { IndexableProperty indexableProperty = annotated.getAnnotation(IndexableProperty.class); if (indexableProperty != null && !indexableProperty.format().isEmpty()) { formatString = indexableProperty.format(); } } } return this; }
@Override public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException { if (property != null) { Annotated annotated = property.getMember(); if (annotated instanceof AnnotatedField || annotated instanceof AnnotatedMethod) { IndexableProperty indexableProperty = annotated.getAnnotation(IndexableProperty.class); if (indexableProperty != null && !indexableProperty.format().isEmpty()) { formatString = indexableProperty.format(); } } } return this; }
@Override public boolean hasIgnoreMarker(AnnotatedMember m) { if (!(m instanceof AnnotatedField) && !(m instanceof AnnotatedMethod)) return false; return (m.getAnnotation(IndexableProperty.class) == null && m.getAnnotation(IndexableComponent.class) == null && m.getAnnotation(IndexableProperties.class) == null); }
private Object findSerializerToUse(Annotated a) { if (a instanceof AnnotatedField || a instanceof AnnotatedMethod) { IndexableComponent indexableComponent = a.getAnnotation(IndexableComponent.class); if (indexableComponent != null && indexableComponent.serializer() != JsonSerializer.class) { return indexableComponent.serializer(); } IndexableProperty indexableProperty = a.getAnnotation(IndexableProperty.class); if (indexableProperty != null) { if (indexableProperty.serializer() != JsonSerializer.class) { return indexableProperty.serializer(); } if (isDate(a)) { // use custom date serializer return DateSerializer.class; } } IndexableProperties indexableProperties = a.getAnnotation(IndexableProperties.class); if (indexableProperties != null && indexableProperties.serializer() != JsonSerializer.class) { return indexableProperties.serializer(); } } else if (a instanceof AnnotatedClass) { // handle class Indexable indexable = a.getAnnotation(Indexable.class); if (indexable != null && indexable.serializer() != JsonSerializer.class) { return indexable.serializer(); } } return null; }
@SuppressWarnings("unchecked") private Class<? extends JsonDeserializer<?>> findDeserializerToUse(Annotated a) { if (a instanceof AnnotatedField || a instanceof AnnotatedMethod) { IndexableComponent indexableComponent = a.getAnnotation(IndexableComponent.class); if (indexableComponent != null && indexableComponent.deserializer() != JsonDeserializer.class) { return (Class<? extends JsonDeserializer<?>>) indexableComponent.deserializer(); } IndexableProperty indexableProperty = a.getAnnotation(IndexableProperty.class); if (indexableProperty != null) { if (indexableProperty.deserializer() != JsonDeserializer.class) { return (Class<? extends JsonDeserializer<?>>) indexableProperty.deserializer(); } if (isDate(a)) { // use custom date deserializer return DateDeserializer.class; } if (indexableProperty.type().equals(TypeEnum.JSON)) { // use custom deserializer for raw json field return RawJsonDeSerializer.class; } } IndexableProperties indexableProperties = a.getAnnotation(IndexableProperties.class); if (indexableProperties != null && indexableProperties.deserializer() != JsonDeserializer.class) { return (Class<? extends JsonDeserializer<?>>) indexableProperties.deserializer(); } } else if (a instanceof AnnotatedClass) { // handle class Indexable indexable = a.getAnnotation(Indexable.class); if (indexable != null && indexable.deserializer() != JsonDeserializer.class) { return (Class<? extends JsonDeserializer<?>>) indexable.deserializer(); } } return null; }
protected List<BeanPropertyWriter> findBeanProperties(SerializerProvider paramSerializerProvider, BeanDescription paramBeanDescription, BeanSerializerBuilder paramBeanSerializerBuilder) { List localList = paramBeanDescription.findProperties(); SerializationConfig localSerializationConfig = paramSerializerProvider.getConfig(); removeIgnorableTypes(localSerializationConfig, paramBeanDescription, localList); if (localSerializationConfig.isEnabled(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS)) removeSetterlessGetters(localSerializationConfig, paramBeanDescription, localList); if (localList.isEmpty()) return null; boolean bool = usesStaticTyping(localSerializationConfig, paramBeanDescription, null); PropertyBuilder localPropertyBuilder = constructPropertyBuilder(localSerializationConfig, paramBeanDescription); ArrayList localArrayList = new ArrayList(localList.size()); TypeBindings localTypeBindings = paramBeanDescription.bindingsForBeanType(); Iterator localIterator = localList.iterator(); while (localIterator.hasNext()) { BeanPropertyDefinition localBeanPropertyDefinition = (BeanPropertyDefinition)localIterator.next(); AnnotatedMember localAnnotatedMember = localBeanPropertyDefinition.getAccessor(); if (localBeanPropertyDefinition.isTypeId()) { if (localAnnotatedMember != null) { if (localSerializationConfig.canOverrideAccessModifiers()) localAnnotatedMember.fixAccess(); paramBeanSerializerBuilder.setTypeId(localAnnotatedMember); } } else { AnnotationIntrospector.ReferenceProperty localReferenceProperty = localBeanPropertyDefinition.findReferenceType(); if ((localReferenceProperty == null) || (!localReferenceProperty.isBackReference())) if ((localAnnotatedMember instanceof AnnotatedMethod)) localArrayList.add(_constructWriter(paramSerializerProvider, localBeanPropertyDefinition, localTypeBindings, localPropertyBuilder, bool, (AnnotatedMethod)localAnnotatedMember)); else localArrayList.add(_constructWriter(paramSerializerProvider, localBeanPropertyDefinition, localTypeBindings, localPropertyBuilder, bool, (AnnotatedField)localAnnotatedMember)); } } return localArrayList; }
public BeanPropertyWriter(BeanPropertyDefinition paramBeanPropertyDefinition, AnnotatedMember paramAnnotatedMember, Annotations paramAnnotations, JavaType paramJavaType1, JsonSerializer<?> paramJsonSerializer, TypeSerializer paramTypeSerializer, JavaType paramJavaType2, boolean paramBoolean, Object paramObject) { this._member = paramAnnotatedMember; this._contextAnnotations = paramAnnotations; this._name = new SerializedString(paramBeanPropertyDefinition.getName()); this._wrapperName = paramBeanPropertyDefinition.getWrapperName(); this._declaredType = paramJavaType1; this._serializer = paramJsonSerializer; PropertySerializerMap localPropertySerializerMap; if (paramJsonSerializer == null) localPropertySerializerMap = PropertySerializerMap.emptyMap(); else localPropertySerializerMap = null; this._dynamicSerializers = localPropertySerializerMap; this._typeSerializer = paramTypeSerializer; this._cfgSerializationType = paramJavaType2; this._isRequired = paramBeanPropertyDefinition.isRequired(); if ((paramAnnotatedMember instanceof AnnotatedField)) { this._accessorMethod = null; this._field = ((Field)paramAnnotatedMember.getMember()); } else if ((paramAnnotatedMember instanceof AnnotatedMethod)) { this._accessorMethod = ((Method)paramAnnotatedMember.getMember()); this._field = null; } else { throw new IllegalArgumentException("Can not pass member of type " + paramAnnotatedMember.getClass().getName()); } this._suppressNulls = paramBoolean; this._suppressableValue = paramObject; this._includeInViews = paramBeanPropertyDefinition.findViews(); this._nullSerializer = null; }
@SuppressWarnings("rawtypes") @Override public String nameForField(MapperConfig config, AnnotatedField field, String defaultName) { return convert(defaultName); }
@SuppressWarnings("unchecked") public BeanPropertyWriter(BeanPropertyDefinition propDef, AnnotatedMember member, Annotations contextAnnotations, JavaType declaredType, JsonSerializer<?> ser, TypeSerializer typeSer, JavaType serType, boolean suppressNulls, Object suppressableValue) { _member = member; _contextAnnotations = contextAnnotations; _name = new SerializedString(propDef.getName()); _declaredType = declaredType; _serializer = (JsonSerializer<Object>) ser; _dynamicSerializers = (ser == null) ? PropertySerializerMap.emptyMap() : null; _typeSerializer = typeSer; _cfgSerializationType = serType; if (member instanceof AnnotatedField) { _accessorMethod = null; _field = (Field) member.getMember(); } else if (member instanceof AnnotatedMethod) { _accessorMethod = (Method) member.getMember(); _field = null; } else { throw new IllegalArgumentException("Can not pass member of type "+member.getClass().getName()); } _suppressNulls = suppressNulls; _suppressableValue = suppressableValue; _includeInViews = propDef.findViews(); // this will be resolved later on, unless nulls are to be suppressed _nullSerializer = null; }
public FieldProperty(BeanPropertyDefinition propDef, JavaType type, TypeDeserializer typeDeser, Annotations contextAnnotations, AnnotatedField field) { super(propDef, type, typeDeser, contextAnnotations); _annotated = field; _field = field.getAnnotated(); }
@Override public String nameForField(MapperConfig<?> config, AnnotatedField field, String defaultName) { return translate(defaultName, field.getRawType()); }
@Override public String nameForField(MapperConfig<?> config, AnnotatedField field, String defaultName) { return convert(field.getName()); }
@Override public String nameForField(MapperConfig<?> config, AnnotatedField field, String defaultName) { String name = config instanceof DeserializationConfig? jsonldName(field): null; return Optional.ofNullable(name).orElse(super.nameForField(config, field, defaultName)); }
@Override public String nameForField(MapperConfig config, AnnotatedField field, String defaultName) { return convertName(defaultName); }
@Override public String nameForField(MapperConfig<?> config, AnnotatedField field, String defaultName) { return OBJECT_ID_FIELD_NAME.equals(defaultName) ? MONGO_ID_FIELD_NAME : super.nameForField(config, field, defaultName); }
public boolean isIgnorableField(AnnotatedField f) { return _cfgCheckTransient && f.hasAnnotation(Transient.class); }
@Override public String nameForField(MapperConfig<?> config, AnnotatedField field, String defaultName) { return convertName(defaultName); }
@Override public String nameForField(MapperConfig<?> config, AnnotatedField field, String defaultName) { return translate(defaultName); }
public FieldProperty(BeanPropertyDefinition paramBeanPropertyDefinition, JavaType paramJavaType, TypeDeserializer paramTypeDeserializer, Annotations paramAnnotations, AnnotatedField paramAnnotatedField) { super(paramBeanPropertyDefinition, paramJavaType, paramTypeDeserializer, paramAnnotations); this._annotated = paramAnnotatedField; this._field = paramAnnotatedField.getAnnotated(); }
@Deprecated public String findDeserializationName(AnnotatedField paramAnnotatedField) { return null; }
@Deprecated public String findSerializationName(AnnotatedField paramAnnotatedField) { return null; }
public String nameForField(MapperConfig<?> paramMapperConfig, AnnotatedField paramAnnotatedField, String paramString) { return paramString; }
public String nameForField(MapperConfig<?> paramMapperConfig, AnnotatedField paramAnnotatedField, String paramString) { return translate(paramString); }
public AnnotatedField getField() { if ((this._member instanceof AnnotatedField)) return (AnnotatedField)this._member; return null; }