コード例 #1
0
  protected BeanPropertyWriter _constructVirtualProperty(
      JsonAppend.Prop prop, MapperConfig<?> config, AnnotatedClass ac) {
    PropertyMetadata metadata =
        prop.required() ? PropertyMetadata.STD_REQUIRED : PropertyMetadata.STD_OPTIONAL;
    PropertyName propName = _propertyName(prop.name(), prop.namespace());
    JavaType type = config.constructType(prop.type());
    // now, then, we need a placeholder for member (no real Field/Method):
    AnnotatedMember member =
        new VirtualAnnotatedMember(
            ac, ac.getRawType(), propName.getSimpleName(), type.getRawClass());
    // and with that and property definition
    SimpleBeanPropertyDefinition propDef =
        SimpleBeanPropertyDefinition.construct(config, member, propName, metadata, prop.include());

    Class<?> implClass = prop.value();

    HandlerInstantiator hi = config.getHandlerInstantiator();
    VirtualBeanPropertyWriter bpw =
        (hi == null) ? null : hi.virtualPropertyWriterInstance(config, implClass);
    if (bpw == null) {
      bpw =
          (VirtualBeanPropertyWriter)
              ClassUtil.createInstance(implClass, config.canOverrideAccessModifiers());
    }

    // one more thing: give it necessary contextual information
    return bpw.withConfig(config, ac, propDef, type);
  }
コード例 #2
0
 @Override
 public TypeResolverBuilder<?> findPropertyTypeResolver(
     MapperConfig<?> config, AnnotatedMember am, JavaType baseType) {
   /* As per definition of @JsonTypeInfo, should only apply to contents of container
    * (collection, map) types, not container types themselves:
    */
   if (baseType.isContainerType()) return null;
   // No per-member type overrides (yet)
   return _findTypeResolver(config, am, baseType);
 }
コード例 #3
0
 @Override
 public TypeResolverBuilder<?> findPropertyContentTypeResolver(
     MapperConfig<?> config, AnnotatedMember am, JavaType containerType) {
   /* First: let's ensure property is a container type: caller should have
    * verified but just to be sure
    */
   if (!containerType.isContainerType()) {
     throw new IllegalArgumentException(
         "Must call method with a container type (got " + containerType + ")");
   }
   return _findTypeResolver(config, am, containerType);
 }
コード例 #4
0
  protected BeanPropertyWriter _constructVirtualProperty(
      JsonAppend.Attr attr, MapperConfig<?> config, AnnotatedClass ac, JavaType type) {
    PropertyMetadata metadata =
        attr.required() ? PropertyMetadata.STD_REQUIRED : PropertyMetadata.STD_OPTIONAL;
    // could add Index, Description in future, if those matter
    String attrName = attr.value();

    // allow explicit renaming; if none, default to attribute name
    PropertyName propName = _propertyName(attr.propName(), attr.propNamespace());
    if (!propName.hasSimpleName()) {
      propName = PropertyName.construct(attrName);
    }
    // now, then, we need a placeholder for member (no real Field/Method):
    AnnotatedMember member =
        new VirtualAnnotatedMember(ac, ac.getRawType(), attrName, type.getRawClass());
    // and with that and property definition
    SimpleBeanPropertyDefinition propDef =
        SimpleBeanPropertyDefinition.construct(config, member, propName, metadata, attr.include());
    // can construct the property writer
    return AttributePropertyWriter.construct(attrName, propDef, ac.getAnnotations(), type);
  }