@Override public void customizeSchema(BeanProperty property, JsonSchema jsonschema) { Optional.ofNullable(property.getAnnotation(Password.class)).ifPresent(annotation -> { if (annotation.title() != null) { ((StringSchema) jsonschema).setTitle(annotation.title()); } if (annotation.pattern() != null) { ((StringSchema) jsonschema).setPattern(annotation.pattern()); } if (annotation.minLenght() != 0) { ((StringSchema) jsonschema).setMinLength(annotation.minLenght()); } if (annotation.maxLenght() != Integer.MAX_VALUE) { ((StringSchema) jsonschema).setMaxLength(annotation.maxLenght()); } }); }
@Override public void customizeSchema(BeanProperty property, JsonSchema jsonschema) { TextField annotation = property.getAnnotation(TextField.class); if (annotation != null) { if (annotation.title() != null) { ((StringSchema) jsonschema).setTitle(annotation.title()); } if (annotation.pattern() != null) { ((StringSchema) jsonschema).setPattern(annotation.pattern()); } if (annotation.minLenght() != 0) { ((StringSchema) jsonschema).setMinLength(annotation.minLenght()); } if (annotation.maxLenght() != Integer.MAX_VALUE) { ((StringSchema) jsonschema).setMaxLength(annotation.maxLenght()); } } }
@Override public JsonSerializer<?> createContextual(SerializerProvider serializerProvider, BeanProperty beanProperty) throws JsonMappingException { if (beanProperty != null) { // System.err.println("beanProperty:" + beanProperty + " name:" + beanProperty.getName() + " type:" + beanProperty.getMember().getGenericType()); Class<A> clazz = annotation(); A anno = beanProperty.getAnnotation(clazz); if (anno == null) { anno = beanProperty.getContextAnnotation(clazz); } if (anno != null) { try { return this.create(clazz, anno, beanProperty); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } } return serializerProvider.findValueSerializer(beanProperty.getType(), beanProperty); } return serializerProvider.findNullValueSerializer(beanProperty); }
@Override public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException { JsonFormat.Value format = findFormatOverrides(ctxt, property, handledType()); if (format != null) { if (format.hasPattern()) { final String pattern = format.getPattern(); final Locale locale = format.hasLocale() ? format.getLocale() : ctxt.getLocale(); DateTimeFormatter df; if (locale == null) { df = DateTimeFormatter.ofPattern(pattern); } else { df = DateTimeFormatter.ofPattern(pattern, locale); } //Issue #69: For instant serializers/deserializers we need to configure the formatter with //a time zone picked up from JsonFormat annotation, otherwise serialization might not work if (format.hasTimeZone()) { df = df.withZone(format.getTimeZone().toZoneId()); } return withDateFormat(df); } // any use for TimeZone? } return this; }
/** * Method called to finalize setup of this deserializer, * after deserializer itself has been registered. This * is needed to handle recursive and transitive dependencies. */ @Override public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException { JsonDeserializer<?> deser = _valueDeserializer; TypeDeserializer typeDeser = _typeDeserializerForValue; if (deser == null) { deser = ctxt.findContextualValueDeserializer(_containerType.getContentType(), property); } if (typeDeser != null) { typeDeser = typeDeser.forProperty(property); } if (deser == _valueDeserializer && typeDeser == _typeDeserializerForValue) { return this; } return withResolved(typeDeser, deser); }
@Override public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException { if (property != null) { JsonFormat.Value format = ctxt.getAnnotationIntrospector().findFormat((Annotated) property.getMember()); if (format != null) { if (format.hasPattern()) { final String pattern = format.getPattern(); final Locale locale = format.hasLocale() ? format.getLocale() : ctxt.getLocale(); DateTimeFormatter df; if (locale == null) { df = DateTimeFormatter.ofPattern(pattern); } else { df = DateTimeFormatter.ofPattern(pattern, locale); } return withDateFormat(df); } // any use for TimeZone? } } return this; }
/** * We need to resolve actual serializer once we know the context; specifically * must know type of property being serialized. * If not known */ @Override public JsonSerializer<?> createContextual(SerializerProvider provider, BeanProperty property) throws JsonMappingException { /* If we have property, should be able to get actual polymorphic type * information. * May need to refine in future, in case nested types are used, since * 'property' refers to field/method and main type, but contents of * that type may also be resolved... in which case this would fail. */ if (property != null) { return new PersistentCollectionSerializer(property, property.getType(), _forceLazyLoading); } return this; }
@Override public void initialize(Bootstrap<?> bootstrap) { final InjectableValues injectableValues = new InjectableValues() { @Override public Object findInjectableValue(Object valueId, DeserializationContext ctxt, BeanProperty forProperty, Object beanInstance) { return null; } }; final ConfigurationFactoryFactory<? extends Configuration> configurationFactoryFactory = bootstrap.getConfigurationFactoryFactory(); ConfigurationFactoryFactory factoryFactory = new ConfigurationFactoryFactory() { @Override public ConfigurationFactory create(Class klass, Validator validator, ObjectMapper objectMapper, String propertyPrefix) { objectMapper.setInjectableValues(injectableValues); //noinspection unchecked return configurationFactoryFactory.create(klass, validator, objectMapper, propertyPrefix); } }; //noinspection unchecked bootstrap.setConfigurationFactoryFactory(factoryFactory); }
@Override public void optionalProperty(BeanProperty prop) throws JsonMappingException { String jsonName = prop.getName(); String fieldName = prop.getMember().getName(); JavaType baseType = prop.getType(); Assert.notNull(baseType, "Missing type for property '" + jsonName + "', field '" + fieldName + "'"); for (JavaType javaType : resolveAllTypes(baseType, typeFactory)) { JsonSerializer<?> ser = getProvider().findValueSerializer(javaType, prop); if (ser == null) { return; } visitType(prop, jsonName, fieldName, javaType, ser); } }
@Override public Object findInjectableValue(Object valueId, DeserializationContext ctxt, BeanProperty forProperty, Object beanInstance) { //if a container, get content type JavaType type = forProperty.getType(); if (type.isCollectionLikeType() | type.isArrayType()){ type = type.getContentType(); } //checking annotation catches properties with interface types if (ObjBase.class.isAssignableFrom(type.getRawClass()) || forProperty.getMember().getAnnotated().isAnnotationPresent(Reference.class)){ try { return super.findInjectableValue(valueId, ctxt, forProperty, beanInstance); } catch (IllegalArgumentException e){ Object value = getValue(valueId, type); return value; } } else { return super.findInjectableValue(valueId, ctxt, forProperty, beanInstance); } }
public JsonSerializer<?> createContextual(SerializerProvider paramSerializerProvider, BeanProperty paramBeanProperty) { JsonSerializer localJsonSerializer1 = this._valueSerializer; if (localJsonSerializer1 == null) { if ((paramSerializerProvider.isEnabled(MapperFeature.USE_STATIC_TYPING)) || (Modifier.isFinal(this._accessorMethod.getReturnType().getModifiers()))) { JavaType localJavaType = paramSerializerProvider.constructType(this._accessorMethod.getGenericReturnType()); JsonSerializer localJsonSerializer2 = paramSerializerProvider.findTypedValueSerializer(localJavaType, false, this._property); return withResolved(paramBeanProperty, localJsonSerializer2, isNaturalTypeWithStdHandling(localJavaType.getRawClass(), localJsonSerializer2)); } } else if ((localJsonSerializer1 instanceof ContextualSerializer)) return withResolved(paramBeanProperty, ((ContextualSerializer)localJsonSerializer1).createContextual(paramSerializerProvider, paramBeanProperty), this._forceTypeInformation); return this; }
public JsonSerializer<?> findConvertingContentSerializer(SerializerProvider paramSerializerProvider, BeanProperty paramBeanProperty, JsonSerializer<?> paramJsonSerializer) { AnnotationIntrospector localAnnotationIntrospector = paramSerializerProvider.getAnnotationIntrospector(); if ((localAnnotationIntrospector != null) && (paramBeanProperty != null)) { Object localObject = localAnnotationIntrospector.findSerializationContentConverter(paramBeanProperty.getMember()); if (localObject != null) { Converter localConverter = paramSerializerProvider.converterInstance(paramBeanProperty.getMember(), localObject); JavaType localJavaType = localConverter.getOutputType(paramSerializerProvider.getTypeFactory()); if (paramJsonSerializer == null) paramJsonSerializer = paramSerializerProvider.findValueSerializer(localJavaType, paramBeanProperty); return new StdDelegatingSerializer(localConverter, localJavaType, paramJsonSerializer); } } return paramJsonSerializer; }
public JsonSerializer<?> createContextual(SerializerProvider paramSerializerProvider, BeanProperty paramBeanProperty) { if (this._delegateSerializer != null) { if ((this._delegateSerializer instanceof ContextualSerializer)) { JsonSerializer localJsonSerializer = ((ContextualSerializer)this._delegateSerializer).createContextual(paramSerializerProvider, paramBeanProperty); if (localJsonSerializer == this._delegateSerializer) return this; return withDelegate(this._converter, this._delegateType, localJsonSerializer); } return this; } JavaType localJavaType1 = this._delegateType; JavaType localJavaType2 = localJavaType1; if (localJavaType1 == null) localJavaType2 = this._converter.getOutputType(paramSerializerProvider.getTypeFactory()); return withDelegate(this._converter, localJavaType2, paramSerializerProvider.findValueSerializer(localJavaType2, paramBeanProperty)); }
protected BeanPropertyWriter _constructWriter(SerializerProvider paramSerializerProvider, BeanPropertyDefinition paramBeanPropertyDefinition, TypeBindings paramTypeBindings, PropertyBuilder paramPropertyBuilder, boolean paramBoolean, AnnotatedMember paramAnnotatedMember) { String str = paramBeanPropertyDefinition.getName(); if (paramSerializerProvider.canOverrideAccessModifiers()) paramAnnotatedMember.fixAccess(); JavaType localJavaType = paramAnnotatedMember.getType(paramTypeBindings); BeanProperty.Std localStd = new BeanProperty.Std(str, localJavaType, paramBeanPropertyDefinition.getWrapperName(), paramPropertyBuilder.getClassAnnotations(), paramAnnotatedMember, paramBeanPropertyDefinition.isRequired()); JsonSerializer localJsonSerializer1 = findSerializerFromAnnotation(paramSerializerProvider, paramAnnotatedMember); JsonSerializer localJsonSerializer2 = localJsonSerializer1; if ((localJsonSerializer1 instanceof ResolvableSerializer)) ((ResolvableSerializer)localJsonSerializer2).resolve(paramSerializerProvider); if ((localJsonSerializer2 instanceof ContextualSerializer)) localJsonSerializer2 = ((ContextualSerializer)localJsonSerializer2).createContextual(paramSerializerProvider, localStd); boolean bool = ClassUtil.isCollectionMapOrArray(localJavaType.getRawClass()); TypeSerializer localTypeSerializer1 = null; if (bool) localTypeSerializer1 = findPropertyContentTypeSerializer(localJavaType, paramSerializerProvider.getConfig(), paramAnnotatedMember); TypeSerializer localTypeSerializer2 = findPropertyTypeSerializer(localJavaType, paramSerializerProvider.getConfig(), paramAnnotatedMember); return paramPropertyBuilder.buildWriter(paramBeanPropertyDefinition, localJavaType, localJsonSerializer2, localTypeSerializer2, localTypeSerializer1, paramAnnotatedMember, paramBoolean); }
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException { KeyDeserializer keyDeser = keyDeserializer; JsonDeserializer<?> deser = valueDeserializer; TypeDeserializer typeDeser = typeDeserializerForValue; if ((keyDeser != null) && (deser != null) && (typeDeser == null)) { return this; } if (keyDeser == null) { keyDeser = ctxt.findKeyDeserializer(mapType.getKeyType(), property); } if (deser == null) { deser = ctxt.findContextualValueDeserializer(mapType.getContentType(), property); } if (typeDeser != null) { typeDeser = typeDeser.forProperty(property); } return withResolved(keyDeser, typeDeser, deser); }
protected JsonDeserializer<?> findConvertingContentDeserializer(DeserializationContext paramDeserializationContext, BeanProperty paramBeanProperty, JsonDeserializer<?> paramJsonDeserializer) { AnnotationIntrospector localAnnotationIntrospector = paramDeserializationContext.getAnnotationIntrospector(); if ((localAnnotationIntrospector != null) && (paramBeanProperty != null)) { Object localObject = localAnnotationIntrospector.findDeserializationContentConverter(paramBeanProperty.getMember()); if (localObject != null) { Converter localConverter = paramDeserializationContext.converterInstance(paramBeanProperty.getMember(), localObject); JavaType localJavaType = localConverter.getInputType(paramDeserializationContext.getTypeFactory()); if (paramJsonDeserializer == null) paramJsonDeserializer = paramDeserializationContext.findContextualValueDeserializer(localJavaType, paramBeanProperty); return new StdDelegatingDeserializer(localConverter, localJavaType, paramJsonDeserializer); } } return paramJsonDeserializer; }
public JsonDeserializer<?> createContextual(DeserializationContext paramDeserializationContext, BeanProperty paramBeanProperty) { JsonDeserializer localJsonDeserializer1 = this._keyDeserializer; JsonDeserializer localJsonDeserializer2 = localJsonDeserializer1; if (localJsonDeserializer1 == null) localJsonDeserializer2 = paramDeserializationContext.findContextualValueDeserializer(this._mapType.getKeyType(), paramBeanProperty); JsonDeserializer localJsonDeserializer3 = this._valueDeserializer; JsonDeserializer localJsonDeserializer4 = localJsonDeserializer3; if (localJsonDeserializer3 == null) localJsonDeserializer4 = paramDeserializationContext.findContextualValueDeserializer(this._mapType.getContentType(), paramBeanProperty); else if ((localJsonDeserializer4 instanceof ContextualDeserializer)) localJsonDeserializer4 = ((ContextualDeserializer)localJsonDeserializer4).createContextual(paramDeserializationContext, paramBeanProperty); TypeDeserializer localTypeDeserializer1 = this._valueTypeDeserializer; TypeDeserializer localTypeDeserializer2 = localTypeDeserializer1; if (localTypeDeserializer1 != null) localTypeDeserializer2 = localTypeDeserializer2.forProperty(paramBeanProperty); return withResolved(localJsonDeserializer2, localJsonDeserializer4, localTypeDeserializer2); }
@Override public JsonSerializer<?> createContextual(SerializerProvider provider, BeanProperty property) throws JsonMappingException { Sensitive sensitive = null; if (property != null) { logger.debug("Checking property for @Sensitive annotation."); sensitive = property.getAnnotation(Sensitive.class); if (sensitive == null) { logger.debug("Checking property for @Sensitive context annotation."); sensitive = property.getContextAnnotation(Sensitive.class); } } if (sensitive != null) { String sensitiveMask = sensitive.mask(); char sensitiveCharacter = sensitive.character(); logger.debug("Found an annotation with mask {} and masking character {}.", sensitiveMask, sensitiveCharacter); return new CensorshipSerializer(sensitiveMask, sensitiveCharacter); } // the default serializer has no mask so use it return this; }
@Override public void customizeSchema(BeanProperty property, JsonSchema jsonschema) { CheckBox annotation = property.getAnnotation(CheckBox.class); if (annotation != null && annotation.title() != null) { ((StringSchema) jsonschema).setTitle(annotation.title()); } }
@Override public void customizeSchema(BeanProperty property, JsonSchema jsonschema) { Number annotation = property.getAnnotation(Number.class); if (annotation != null && annotation.title() != null) { ((SimpleTypeSchema) jsonschema).setTitle(annotation.title()); } }
@Override public void customizeSchema(BeanProperty property, JsonSchema jsonschema) { RadioBox annotation = property.getAnnotation(RadioBox.class); if (annotation != null && annotation.title() != null) { ((StringSchema) jsonschema).setTitle(annotation.title()); } }
@Override public void customizeSchema(BeanProperty property, JsonSchema jsonschema) { ComboBox annotation = property.getAnnotation(ComboBox.class); if (annotation != null && annotation.title() != null) { ((StringSchema) jsonschema).setTitle(annotation.title()); } }
@Override public void customizeSchema(BeanProperty property, JsonSchema jsonschema) { Optional.ofNullable(property.getAnnotation(TextArea.class)).ifPresent(annotation -> { if (annotation.title() != null) { ((StringSchema) jsonschema).setTitle(annotation.title()); } if (annotation.minLenght() != 0) { ((StringSchema) jsonschema).setMinLength(annotation.minLenght()); } if (annotation.maxLenght() != Integer.MAX_VALUE) { ((StringSchema) jsonschema).setMaxLength(annotation.maxLenght()); } }); }
@Override public JsonDeserializer createContextual(DeserializationContext ctx, BeanProperty property) throws JsonMappingException { Class rawCls = ctx.getContextualType().getRawClass(); Class<Enum> enumCls = (Class<Enum>) rawCls; CustomEnumDeserializer clone = new CustomEnumDeserializer(prop); clone.setEnumCls(enumCls); return clone; }
@Override public Object findInjectableValue(Object valueId, DeserializationContext ctxt, BeanProperty forProperty, Object beanInstance) { if(valueId != null && CURRENT_NAME.equals(valueId)){ return ctxt.getParser().getParsingContext().getCurrentName(); } return delegate.findInjectableValue(valueId, ctxt, forProperty, beanInstance); }
@Override public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException { if (property != null) { JsonFormat.Value format = ctxt.getAnnotationIntrospector().findFormat(property.getMember()); if (format != null && Objects.equals(TransactionSerializer.BASE64_FORMAT, format.getPattern())) { return new Base64TransactionDeserializer(formatter); } } return new HexTransactionDeserializer(formatter); }
@Override public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException { defaultDeserializer = (MapDeserializer) defaultDeserializer.createContextual(ctxt, property); return this; }
@Override public JsonDeserializer<?> createContextual(DeserializationContext deserializationContext, BeanProperty beanProperty) { JavaType javaType = deserializationContext.getContextualType() != null ? deserializationContext.getContextualType() : extractType(beanProperty.getMember()); Annotation[] annotations = beanProperty != null ? beanProperty.getMember().getAnnotated().getAnnotations() : new Annotation[0]; AnnotatedType detectedType = ClassUtils.addAnnotations(TypeUtils.toJavaType(javaType), annotations); if (inputConverter.supports(detectedType)) { return new ConvertingDeserializer(detectedType, inputConverter, environment, (ObjectMapper) deserializationContext.getParser().getCodec()); } else { return new DefaultDeserializer(javaType); } }
@Override public JsonSerializer<?> createContextual(SerializerProvider provider, BeanProperty property) throws JsonMappingException { if (delegate instanceof ContextualSerializer) { return new DeepEmptyCheckingSerializer<>( ((ContextualSerializer) delegate).createContextual(provider, property)); } return this; }
/** * Override to preserve the delegating behavior when a contextualized serializer is created. */ @Override public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException { if (_delegateSerializer instanceof ContextualSerializer) { JsonSerializer<?> contextualDelegate = ((ContextualSerializer) _delegateSerializer).createContextual(prov, property); // Check for different instance if (contextualDelegate != _delegateSerializer) { return new DelegatingMapSerializer(contextualDelegate); } } return this; }
@Override public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException { Class<?> resourceContentType = ctxt.getContextualType().getBindings().getTypeParameters().get(0).getRawClass(); return new ResourceDeserializer(resourceContentType, typeResolver, configuration); }
@SuppressWarnings("unchecked") @Override public JsonDeserializer<T> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException { InstantDeserializer<T> deserializer = (InstantDeserializer<T>)super.createContextual(ctxt, property); if (deserializer != this) { JsonFormat.Value val = findFormatOverrides(ctxt, property, handledType()); if (val != null) { return new InstantDeserializer<>(deserializer, val.getFeature(JsonFormat.Feature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)); } } return this; }
public HalLinkListSerializer(BeanProperty property, CurieProvider curieProvider, EmbeddedMapper mapper, MessageSourceAccessor messageSource) { super(List.class, false); this.property = property; this.curieProvider = curieProvider; this.mapper = mapper; this.messageSource = messageSource; }
/** * Creates a new {@link OptionalListJackson2Serializer} using the given {@link BeanProperty}. * * @param property */ public OptionalListJackson2Serializer(BeanProperty property) { super(List.class, false); this.property = property; this.serializers = new HashMap<Class<?>, JsonSerializer<Object>>(); }
@Override public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException { JavaType vc = property.getType().getContentType(); HalResourcesDeserializer des = new HalResourcesDeserializer(vc); return des; }
@Override public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException { checkNotNull(ctxt, "Null DeserializationContext."); JavaType type = checkNotNull(ctxt.getContextualType(), "Invalid type: %s", getClass()); JavaType[] params = type.findTypeParameters(ValueProvider.class); if (params.length != 1) { throw new RuntimeException( "Unable to derive type for ValueProvider: " + type.toString()); } JavaType param = params[0]; return new Deserializer(param); }
@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; }
public PersistentCollectionSerializer(BeanProperty property, JavaType type, boolean forceLazyLoading) { _property = property; _serializationType = type; _forceLazyLoading = forceLazyLoading; }