com.fasterxml.jackson.databind.BeanProperty Java Examples

The following examples show how to use com.fasterxml.jackson.databind.BeanProperty. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JSR310StringParsableDeserializer.java    From jackson-modules-java8 with Apache License 2.0 6 votes vote down vote up
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
        BeanProperty property) throws JsonMappingException
{
    JsonFormat.Value format = findFormatOverrides(ctxt, property, handledType());
    JSR310StringParsableDeserializer deser = this;
    if (format != null) {
        if (format.hasLenient()) {
            Boolean leniency = format.getLenient();
            if (leniency != null) {
                deser = this.withLeniency(leniency);
            }
        }
    }
    return deser;
}
 
Example #2
Source File: DoubleSpecifySerialize.java    From jframework with Apache License 2.0 6 votes vote down vote up
@Override
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException {
    // 为空直接跳过
    if (property == null) {
        return prov.findNullValueSerializer(property);
    }
    // 非 Double 类直接跳过
    if (Objects.equals(property.getType().getRawClass(), Double.class)) {
        DoubleSpecify doubleSpecify = property.getAnnotation(DoubleSpecify.class);
        if (doubleSpecify == null) {
            doubleSpecify = property.getContextAnnotation(DoubleSpecify.class);
        }
        // 如果能得到注解,就将注解的 value 传入 DoubleSpecifySerialize
        if (doubleSpecify != null) {
            return new DoubleSpecifySerialize(doubleSpecify.value());
        }
    }
    return prov.findValueSerializer(property.getType(), property);
}
 
Example #3
Source File: BigDecimalSpecifySerialize.java    From jframework with Apache License 2.0 6 votes vote down vote up
@Override
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException {
    // 为空直接跳过
    if (property == null) {
        return prov.findNullValueSerializer(property);
    }
    // 非 BigDecimal 类直接跳过
    if (Objects.equals(property.getType().getRawClass(), BigDecimal.class)) {
        BigDecimalSpecify doubleSpecify = property.getAnnotation(BigDecimalSpecify.class);
        if (doubleSpecify == null) {
            doubleSpecify = property.getContextAnnotation(BigDecimalSpecify.class);
        }
        // 如果能得到注解,就将注解的 value 传入 BigDecimalSpecifySerialize
        if (doubleSpecify != null) {
            return new BigDecimalSpecifySerialize(doubleSpecify.value());
        }
    }
    return prov.findValueSerializer(property.getType(), property);
}
 
Example #4
Source File: UntypedObjectDeserializer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * We only use contextualization for optimizing the case where no customization
 * occurred; if so, can slip in a more streamlined version.
 */
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
        BeanProperty property) throws JsonMappingException
{
    // 14-Jun-2017, tatu: [databind#1625]: may want to block merging, for root value
    boolean preventMerge = (property == null)
            && Boolean.FALSE.equals(ctxt.getConfig().getDefaultMergeable(Object.class));
    // 20-Apr-2014, tatu: If nothing custom, let's use "vanilla" instance,
    //     simpler and can avoid some of delegation
    if ((_stringDeserializer == null) && (_numberDeserializer == null)
            && (_mapDeserializer == null) && (_listDeserializer == null)
            &&  getClass() == UntypedObjectDeserializer.class) {
        return Vanilla.instance(preventMerge);
    }
    if (preventMerge != _nonMerging) {
        return new UntypedObjectDeserializer(this, preventMerge);
    }
    return this;
}
 
Example #5
Source File: TextFieldSchemaDecorator.java    From sf-java-ui with MIT License 6 votes vote down vote up
@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());
		}
	}
}
 
Example #6
Source File: JSR310DateTimeDeserializerBase.java    From bootique with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #7
Source File: PasswordSchemaDecorator.java    From sf-java-ui with MIT License 6 votes vote down vote up
@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());
		}
	});
}
 
Example #8
Source File: InstantDeserializer.java    From jackson-modules-java8 with Apache License 2.0 6 votes vote down vote up
@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) {
            deserializer = new InstantDeserializer<>(deserializer, val.getFeature(JsonFormat.Feature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE));
            if (val.hasLenient()) {
                Boolean leniency = val.getLenient();
                if (leniency != null) {
                    deserializer = deserializer.withLeniency(leniency);
                }
            }
        }
    }
    return deserializer;
}
 
Example #9
Source File: GuiceInjectableValues.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
@Override
public Object findInjectableValue(
    Object valueId, DeserializationContext ctxt, BeanProperty forProperty, Object beanInstance
)
{
  return injector.getInstance((Key<?>) valueId);
}
 
Example #10
Source File: AsExternalTypeDeserializer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public TypeDeserializer forProperty(BeanProperty prop) {
    if (prop == _property) { // usually if it's null
        return this;
    }
    return new AsExternalTypeDeserializer(this, prop);
}
 
Example #11
Source File: DatabaseReader.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Object findInjectableValue(final Object valueId, final DeserializationContext ctxt, final BeanProperty forProperty, final Object beanInstance) throws JsonMappingException {
    if ("ip_address".equals(valueId)) {
        return ip;
    } else if ("traits".equals(valueId)) {
        return new Traits(ip);
    } else if ("locales".equals(valueId)) {
        return locales;
    }

    return null;
}
 
Example #12
Source File: TypeDeserializerBase.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected TypeDeserializerBase(TypeDeserializerBase src, BeanProperty property)
{
    _baseType = src._baseType;
    _idResolver = src._idResolver;
    _typePropertyName = src._typePropertyName;
    _typeIdVisible = src._typeIdVisible;
    _deserializers = src._deserializers;
    _defaultImpl = src._defaultImpl;
    _defaultImplDeserializer = src._defaultImplDeserializer;
    _property = property;
}
 
Example #13
Source File: ValueSerializer.java    From cyclops with Apache License 2.0 5 votes vote down vote up
@Override
protected ReferenceTypeSerializer<Value<?>> withResolved(BeanProperty prop,
                                                          TypeSerializer vts, JsonSerializer<?> valueSer,
                                                          NameTransformer unwrapper)
{
  return new ValueSerializer(this, prop, vts, valueSer, unwrapper,
    _suppressableValue, _suppressNulls);
}
 
Example #14
Source File: TestDefaultIndexInfoBuilder.java    From suro with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreation() throws IOException {
    String desc = "{\n" +
            "    \"type\": \"default\",\n" +
            "    \"indexTypeMap\":{\"routingkey1\":\"index1:type1\", \"routingkey2\":\"index2:type2\"},\n" +
            "    \"idFields\":{\"routingkey\": [\"f1\", \"f2\", \"ts_minute\"]},\n" +
            "    \"timestamp\": {\"field\":\"ts\"},\n" +
            "    \"indexSuffixFormatter\":{\"type\": \"date\", \"properties\":{\"dateFormat\":\"YYYYMMdd\"}}\n" +
            "}";
    jsonMapper.setInjectableValues(new InjectableValues() {
                @Override
                public Object findInjectableValue(
                        Object valueId,
                        DeserializationContext ctxt,
                        BeanProperty forProperty,
                        Object beanInstance
                ) {
                    if (valueId.equals(ObjectMapper.class.getCanonicalName())) {
                        return jsonMapper;
                    } else {
                        return null;
                    }
                }
            });
    DateTime dt = new DateTime("2014-10-12T12:12:12.000Z");

    Map<String, Object> msg = new ImmutableMap.Builder<String, Object>()
            .put("f1", "v1")
            .put("f2", "v2")
            .put("f3", "v3")
            .put("ts", dt.getMillis())
            .build();
    IndexInfoBuilder builder = jsonMapper.readValue(desc, new TypeReference<IndexInfoBuilder>(){});
    IndexInfo info = builder.create(new Message("routingkey", jsonMapper.writeValueAsBytes(msg)));
    assertEquals(info.getId(), ("v1v2" + dt.getMillis() / 60000));
}
 
Example #15
Source File: ConvertingDeserializer.java    From graphql-spqr with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> createContextual(DeserializationContext deserializationContext, BeanProperty beanProperty) {
    JavaType javaType = deserializationContext.getContextualType() != null ? deserializationContext.getContextualType() : extractType(beanProperty.getMember());
    Annotation[] annotations = annotations(beanProperty);
    AnnotatedType detectedType = environment.typeTransformer.transform(ClassUtils.addAnnotations(TypeUtils.toJavaType(javaType), annotations));
    JavaType substituteType = deserializationContext.getTypeFactory().constructType(environment.getMappableInputType(detectedType).getType());
    if (inputConverter.supports(detectedType)) {
        return new ConvertingDeserializer(detectedType, substituteType, inputConverter, environment, objectMapper);
    } else {
        return new DefaultDeserializer(javaType);
    }
}
 
Example #16
Source File: RefKeyHandler.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@Override
public RefKeyHandler createContextualKey(DeserializationContext ctxt, BeanProperty property)
        throws JsonMappingException {
    //noinspection VariableNotUsedInsideIf
    return _keyDeserializer == null ?
            new RefKeyHandler(_keyType, ctxt.findKeyDeserializer(_keyType, property)) :
            this;
}
 
Example #17
Source File: OptionSerializer.java    From cyclops with Apache License 2.0 5 votes vote down vote up
@Override
protected ReferenceTypeSerializer<Option<?>> withResolved(BeanProperty prop,
                                                          TypeSerializer vts, JsonSerializer<?> valueSer,
                                                          NameTransformer unwrapper)
{
  return new OptionSerializer(this, prop, vts, valueSer, unwrapper,
    _suppressableValue, _suppressNulls);
}
 
Example #18
Source File: RefRefMapIterableSerializer.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
protected RefRefMapIterableSerializer(
        RefRefMapIterableSerializer src, BeanProperty property,
        JsonSerializer<?> keySerializer, TypeSerializer vts, JsonSerializer<?> valueSerializer,
        Set<String> ignoredEntries
) {
    super(src, property, keySerializer, vts, valueSerializer, ignoredEntries);
}
 
Example #19
Source File: WebElementDeserializerTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
void shouldReturnTypeBasedDeserializer(String type, JsonDeserializer<?> expected)
{
    BeanProperty property = mock(BeanProperty.class);
    JavaType javaType = mock(JavaType.class);
    when(property.getType()).thenReturn(javaType);
    when(javaType.getGenericSignature()).thenReturn(type);
    assertEquals(expected, deserializer.createContextual(null, property));
}
 
Example #20
Source File: RefStdDeserializer.java    From gwt-jackson with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> createContextual( DeserializationContext ctxt, BeanProperty property ) throws JsonMappingException {
    if ( ctxt.getContextualType() == null || ctxt.getContextualType().containedType( 0 ) == null ) {
        throw JsonMappingException.from( ctxt, "Cannot deserialize Ref<T>. Cannot find the Generic Type T." );
    }
    return new RefStdDeserializer( ctxt.getContextualType().containedType( 0 ) );
}
 
Example #21
Source File: RangeSetSerializer.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@Override
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) {
    if (property == null) return this;
    final RangeSetSerializer serializer = new RangeSetSerializer();
    serializer.genericRangeListType = prov.getTypeFactory()
            .constructCollectionType(List.class,
                    prov.getTypeFactory().constructParametricType(
                            Range.class, property.getType().containedType(0)));
    return serializer;
}
 
Example #22
Source File: CollectionSerializer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @deprecated since 2.6
 */
@Deprecated // since 2.6
public CollectionSerializer(JavaType elemType, boolean staticTyping, TypeSerializer vts,
        BeanProperty property, JsonSerializer<Object> valueSerializer) {
    // note: assumption is 'property' is always passed as null
    this(elemType, staticTyping, vts, valueSerializer);
}
 
Example #23
Source File: TextAreaSchemaDecorator.java    From sf-java-ui with MIT License 5 votes vote down vote up
@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());
		}
	});
}
 
Example #24
Source File: TrampolineSerializer.java    From cyclops with Apache License 2.0 5 votes vote down vote up
@Override
protected ReferenceTypeSerializer<Trampoline<?>> withResolved(BeanProperty prop,
                                                          TypeSerializer vts, JsonSerializer<?> valueSer,
                                                          NameTransformer unwrapper)
{
  return new TrampolineSerializer(this, prop, vts, valueSer, unwrapper,
    _suppressableValue, _suppressNulls);
}
 
Example #25
Source File: ObjectMapperUtil.java    From endpoints-java with Apache License 2.0 5 votes vote down vote up
@Override
public JsonSerializer<?> createContextual(SerializerProvider provider, BeanProperty property)
    throws JsonMappingException {
  if (delegate instanceof ContextualSerializer) {
    return new DeepEmptyCheckingSerializer<>(
        ((ContextualSerializer) delegate).createContextual(provider, property));
  }
  return this;
}
 
Example #26
Source File: ComboBoxSchemaDecorator.java    From sf-java-ui with MIT License 5 votes vote down vote up
@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());
	}
}
 
Example #27
Source File: FieldDocumentationObjectVisitor.java    From spring-auto-restdocs with Apache License 2.0 5 votes vote down vote up
private boolean shouldSkip(BeanProperty prop) {
    Class<?> rawClass = prop.getType().getContentType() != null
            ? prop.getType().getContentType().getRawClass()
            : prop.getType().getRawClass();
    return SKIPPED_FIELDS.contains(prop.getName())
            || SKIPPED_CLASSES.contains(rawClass.getCanonicalName());
}
 
Example #28
Source File: LazyJsonModule.java    From emodb with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #29
Source File: RadioBoxSchemaDecorator.java    From sf-java-ui with MIT License 5 votes vote down vote up
@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());
	}
}
 
Example #30
Source File: CheckBoxSchemaDecorator.java    From sf-java-ui with MIT License 5 votes vote down vote up
@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());
	}
}