com.fasterxml.jackson.databind.introspect.AnnotatedMember.getValue()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中com.fasterxml.jackson.databind.introspect.AnnotatedMember.getValue()方法的一些代码示例,展示了AnnotatedMember.getValue()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AnnotatedMember.getValue()方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.introspect.AnnotatedMember
类名称:AnnotatedMember
方法名:getValue

AnnotatedMember.getValue介绍

[英]Optional method that can be used to access the value of this member on given object, if this is a supported operation for member type.

This is implemented for fields and no-argument member methods; but not for constructor parameters or other types of methods (like static methods)
[中]可选方法,可用于访问给定对象上此成员的值(如果这是成员类型支持的操作)。
这是为字段和无参数成员方法实现的;但不适用于构造函数参数或其他类型的方法(如静态方法)

代码示例

代码示例来源:origin: redisson/redisson

@Deprecated // since 2.9
protected final String _customTypeId(Object bean)
{
  final Object typeId = _typeId.getValue(bean);
  if (typeId == null) {
    return "";
  }
  return (typeId instanceof String) ? (String) typeId : typeId.toString();
}

代码示例来源:origin: redisson/redisson

/**
 * @since 2.9
 */
public static EnumResolver constructUsingMethod(Class<Enum<?>> enumCls,
    AnnotatedMember accessor,
    AnnotationIntrospector ai)
{
  Enum<?>[] enumValues = enumCls.getEnumConstants();
  HashMap<String, Enum<?>> map = new HashMap<String, Enum<?>>();
  // from last to first, so that in case of duplicate values, first wins
  for (int i = enumValues.length; --i >= 0; ) {
    Enum<?> en = enumValues[i];
    try {
      Object o = accessor.getValue(en);
      if (o != null) {
        map.put(o.toString(), en);
      }
    } catch (Exception e) {
      throw new IllegalArgumentException("Failed to access @JsonValue of Enum value "+en+": "+e.getMessage());
    }
  }
  Enum<?> defaultEnum = (ai != null) ? ai.findDefaultEnumValue(enumCls) : null;
  return new EnumResolver(enumCls, enumValues, map, defaultEnum);
}

代码示例来源:origin: redisson/redisson

/**
 * @since 2.9
 */
protected final WritableTypeId _typeIdDef(TypeSerializer typeSer,
    Object bean, JsonToken valueShape) {
  if (_typeId == null) {
    return typeSer.typeId(bean, valueShape);
  }
  Object typeId = _typeId.getValue(bean);
  if (typeId == null) {
    // 28-Jun-2017, tatu: Is this really needed? Unchanged from 2.8 but...
    typeId = "";
  }
  return typeSer.typeId(bean, valueShape, typeId);
}

代码示例来源:origin: redisson/redisson

public void getAndSerialize(Object bean, JsonGenerator gen, SerializerProvider provider)
  throws Exception
{
  Object value = _accessor.getValue(bean);
  if (value == null) {
    return;
  }
  if (!(value instanceof Map<?,?>)) {
    provider.reportBadDefinition(_property.getType(), String.format(
        "Value returned by 'any-getter' %s() not java.util.Map but %s",
        _accessor.getName(), value.getClass().getName()));
  }
  // 23-Feb-2015, tatu: Nasty, but has to do (for now)
  if (_mapSerializer != null) {
    _mapSerializer.serializeFields((Map<?,?>) value, gen, provider);
    return;
  }
  _serializer.serialize(value, gen, provider);
}

代码示例来源:origin: redisson/redisson

enums.add(String.valueOf(_accessor.getValue(en)));
} catch (Exception e) {
  Throwable t = e;

代码示例来源:origin: redisson/redisson

/**
 * Accessor used to find out "default value" for given property, to use for
 * comparing values to serialize, to determine whether to exclude value from serialization with
 * inclusion type of {@link com.fasterxml.jackson.annotation.JsonInclude.Include#NON_DEFAULT}.
 * This method is called when we specifically want to know default value within context
 * of a POJO, when annotation is within containing class, and not for property or
 * defined as global baseline.
 *<p>
 * Note that returning of pseudo-type
 * {@link com.fasterxml.jackson.annotation.JsonInclude.Include#NON_EMPTY} requires special handling.
 *
 * @since 2.7
 * @deprecated Since 2.9 since this will not allow determining difference between "no default instance"
 *    case and default being `null`.
 */
@Deprecated // since 2.9
protected Object getPropertyDefaultValue(String name, AnnotatedMember member,
    JavaType type)
{
  Object defaultBean = getDefaultBean();
  if (defaultBean == null) {
    return getDefaultValue(type);
  }
  try {
    return member.getValue(defaultBean);
  } catch (Exception e) {
    return _throwWrapped(e, name, defaultBean);
  }
}

代码示例来源:origin: redisson/redisson

/**
 * @since 2.3
 */
public void getAndFilter(Object bean, JsonGenerator gen, SerializerProvider provider,
    PropertyFilter filter)
  throws Exception
{
  Object value = _accessor.getValue(bean);
  if (value == null) {
    return;
  }
  if (!(value instanceof Map<?,?>)) {
    provider.reportBadDefinition(_property.getType(),
        String.format("Value returned by 'any-getter' (%s()) not java.util.Map but %s",
        _accessor.getName(), value.getClass().getName()));
  }
  // 19-Oct-2014, tatu: Should we try to support @JsonInclude options here?
  if (_mapSerializer != null) {
    _mapSerializer.serializeFilteredAnyProperties(provider, gen, bean,(Map<?,?>) value,
        filter, null);
    return;
  }
  // ... not sure how custom handler would do it
  _serializer.serialize(value, gen, provider);
}

代码示例来源:origin: redisson/redisson

@Override
public void deserializeAndSet(JsonParser p, DeserializationContext ctxt,
    Object instance) throws IOException
{
  Object oldValue = _accessor.getValue(instance);
  Object newValue;
  // 20-Oct-2016, tatu: Couple of possibilities of how to proceed; for
  //    now, default to "normal" handling without merging
  if (oldValue == null) {
    newValue = delegate.deserialize(p, ctxt);
  } else {
    newValue = delegate.deserializeWith(p, ctxt, oldValue);
  }
  if (newValue != oldValue) {
    // 18-Apr-2017, tatu: Null handling should occur within delegate, which may
    //     set/skip/transform it, or throw an exception.
    delegate.set(instance, newValue);
  }
}

代码示例来源:origin: redisson/redisson

@Override
public Object deserializeSetAndReturn(JsonParser p,
    DeserializationContext ctxt, Object instance) throws IOException
{
  Object oldValue = _accessor.getValue(instance);
  Object newValue;
  // 20-Oct-2016, tatu: Couple of possibilities of how to proceed; for
  //    now, default to "normal" handling without merging
  if (oldValue == null) {
    newValue = delegate.deserialize(p, ctxt);
  } else {
    newValue = delegate.deserializeWith(p, ctxt, oldValue);
  }
  // 23-Oct-2016, tatu: One possible complication here; should we always
  //    try calling setter on builder? Presumably should not be required,
  //    but may need to revise
  if (newValue != oldValue) {
    // 31-Oct-2016, tatu: Basically should just ignore as null can't really
    //    contribute to merging.
    if (newValue != null) {
      return delegate.setAndReturn(instance, newValue);
    }
  }
  return instance;
}

代码示例来源:origin: redisson/redisson

@Override
public void serialize(Object bean, JsonGenerator gen, SerializerProvider prov) throws IOException
{
  try {
    Object value = _accessor.getValue(bean);
    if (value == null) {
      prov.defaultSerializeNull(gen);
      return;
    }
    JsonSerializer<Object> ser = _valueSerializer;
    if (ser == null) {
      Class<?> c = value.getClass();
      /* 10-Mar-2010, tatu: Ideally we would actually separate out type
       *   serializer from value serializer; but, alas, there's no access
       *   to serializer factory at this point... 
       */
      // let's cache it, may be needed soon again
      ser = prov.findTypedValueSerializer(c, true, _property);
    }
    ser.serialize(value, gen, prov);
  } catch (Exception e) {
    wrapAndThrow(prov, e, bean, _accessor.getName() + "()");
  }
}

代码示例来源:origin: redisson/redisson

value = _accessor.getValue(bean);

代码示例来源:origin: redisson/redisson

valueToSuppress = am.getValue(defaultBean);
} catch (Exception e) {
  _throwWrapped(e, propDef.getName(), defaultBean);

代码示例来源:origin: com.eclipsesource.jaxrs/jersey-all

protected final String _customTypeId(Object bean)
{
  final Object typeId = _typeId.getValue(bean);
  if (typeId == null) {
    return "";
  }
  return (typeId instanceof String) ? (String) typeId : typeId.toString();
}

代码示例来源:origin: Nextdoor/bender

protected final String _customTypeId(Object bean)
{
  final Object typeId = _typeId.getValue(bean);
  if (typeId == null) {
    return "";
  }
  return (typeId instanceof String) ? (String) typeId : typeId.toString();
}

代码示例来源:origin: com.fasterxml.jackson.core/com.springsource.com.fasterxml.jackson.core.jackson-databind

private final String _customTypeId(Object bean)
{
  final Object typeId = _typeId.getValue(bean);
  if (typeId == null) {
    return "";
  }
  return (typeId instanceof String) ? (String) typeId : typeId.toString();
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics

private final String _customTypeId(Object bean)
{
  final Object typeId = _typeId.getValue(bean);
  if (typeId == null) {
    return "";
  }
  return (typeId instanceof String) ? (String) typeId : typeId.toString();
}

代码示例来源:origin: com.jwebmp.jackson.core/jackson-databind

@Deprecated // since 2.9
protected final String _customTypeId(Object bean)
{
  final Object typeId = _typeId.getValue(bean);
  if (typeId == null) {
    return "";
  }
  return (typeId instanceof String) ? (String) typeId : typeId.toString();
}

代码示例来源:origin: com.eclipsesource.jaxrs/jersey-all

protected Object getDefaultValue(String name, AnnotatedMember member)
{
  Object defaultBean = getDefaultBean();
  try {
    return member.getValue(defaultBean);
  } catch (Exception e) {
    return _throwWrapped(e, name, defaultBean);
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics

protected Object getDefaultValue(String name, AnnotatedMember member)
{
  Object defaultBean = getDefaultBean();
  try {
    return member.getValue(defaultBean);
  } catch (Exception e) {
    return _throwWrapped(e, name, defaultBean);
  }
}

代码示例来源:origin: com.fasterxml.jackson.core/com.springsource.com.fasterxml.jackson.core.jackson-databind

protected Object getDefaultValue(String name, AnnotatedMember member)
{
  Object defaultBean = getDefaultBean();
  try {
    return member.getValue(defaultBean);
  } catch (Exception e) {
    return _throwWrapped(e, name, defaultBean);
  }
}

相关文章