當前位置: 首頁>>代碼示例>>Java>>正文


Java As類代碼示例

本文整理匯總了Java中com.fasterxml.jackson.annotation.JsonTypeInfo.As的典型用法代碼示例。如果您正苦於以下問題:Java As類的具體用法?Java As怎麽用?Java As使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


As類屬於com.fasterxml.jackson.annotation.JsonTypeInfo包,在下文中一共展示了As類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addJsonTypeInfo

import com.fasterxml.jackson.annotation.JsonTypeInfo.As; //導入依賴的package包/類
private void addJsonTypeInfo(JDefinedClass klass, ObjectTypeDeclaration type) {
    if (!context.getConfig().isJacksonTypeInfo()) {
        return;
    }
    if (type.discriminator() == null) {
        return;
    }
    List<String> derivedTypes = context.getApiModel().findDerivedTypes(type.name());
    if (derivedTypes.isEmpty()) {
        return;
    }
    JAnnotationUse typeInfo = klass.annotate(JsonTypeInfo.class);
    typeInfo.param("use", Id.NAME);
    typeInfo.param("include", As.EXISTING_PROPERTY);
    typeInfo.param("property", type.discriminator());

    JAnnotationUse subTypes = klass.annotate(JsonSubTypes.class);
    JAnnotationArrayMember typeArray = subTypes.paramArray(VALUE);

    for (String derivedType : derivedTypes) {
        JDefinedClass subtype = pkg._getClass(derivedType);
        typeArray.annotate(Type.class).param(VALUE, subtype);
    }
}
 
開發者ID:ops4j,項目名稱:org.ops4j.ramler,代碼行數:25,代碼來源:PojoGeneratingApiVisitor.java

示例2: generateTypeInfo

import com.fasterxml.jackson.annotation.JsonTypeInfo.As; //導入依賴的package包/類
/**
 * Build the code to initialize a {@link TypeSerializationInfo} or {@link TypeDeserializationInfo}.
 *
 * @param typeInfo the type information obtained through the {@link JsonTypeInfo} annotation
 * @return the code built
 */
protected final CodeBlock generateTypeInfo( BeanTypeInfo typeInfo ) {

    Class type;
    ImmutableMap<JClassType, String> mapTypeToMetadata;
    if ( isSerializer() ) {
        type = TypeSerializationInfo.class;
        mapTypeToMetadata = typeInfo.getMapTypeToSerializationMetadata();
    } else {
        type = TypeDeserializationInfo.class;
        mapTypeToMetadata = typeInfo.getMapTypeToDeserializationMetadata();
    }

    CodeBlock.Builder builder = CodeBlock.builder()
            .add( "new $T($T.$L, $S)", type, As.class, typeInfo.getInclude(), typeInfo.getPropertyName() )
            .indent()
            .indent();

    for ( Entry<JClassType, String> entry : mapTypeToMetadata.entrySet() ) {
        builder.add( "\n.addTypeInfo($T.class, $S)", rawName( entry.getKey() ), entry.getValue() );
    }

    return builder.unindent().unindent().build();
}
 
開發者ID:nmorel,項目名稱:gwt-jackson,代碼行數:30,代碼來源:AbstractBeanJsonCreator.java

示例3: processProperties

import com.fasterxml.jackson.annotation.JsonTypeInfo.As; //導入依賴的package包/類
/**
 * Process the properties of the bean to find additionnal informations like @JsonValue.
 *
 * @param configuration the configuration
 * @param logger the logger
 * @param typeOracle the oracle
 * @param beanInfo the previous bean information
 * @param properties the properties of the bean
 * @return the new informations about the bean and its properties
 */
public static BeanInfo processProperties( RebindConfiguration configuration, TreeLogger logger, JacksonTypeOracle typeOracle,
                                          BeanInfo beanInfo, PropertiesContainer properties ) {
    if ( !properties.getValuePropertyInfo().isPresent() && !properties.getAnyGetterPropertyInfo().isPresent() && !properties
            .getAnySetterPropertyInfo().isPresent() ) {
        return beanInfo;
    }

    BeanInfoBuilder builder = new BeanInfoBuilder( beanInfo );
    builder.setValuePropertyInfo( properties.getValuePropertyInfo() );

    if ( properties.getValuePropertyInfo().isPresent() && beanInfo.getTypeInfo().isPresent() && As.PROPERTY.equals( beanInfo
            .getTypeInfo().get().getInclude() ) ) {
        // if the bean has type info on property with @JsonValue, we change it to WRAPPER_ARRAY because the value may not be an object
        BeanTypeInfo typeInfo = beanInfo.getTypeInfo().get();
        builder.setTypeInfo( Optional.of( new BeanTypeInfo( typeInfo.getUse(), As.WRAPPER_ARRAY, typeInfo
                .getPropertyName(), typeInfo.getMapTypeToSerializationMetadata(), typeInfo.getMapTypeToDeserializationMetadata() ) ) );
    }

    builder.setAnyGetterPropertyInfo( properties.getAnyGetterPropertyInfo() );
    builder.setAnySetterPropertyInfo( properties.getAnySetterPropertyInfo() );

    return builder.build();
}
 
開發者ID:nmorel,項目名稱:gwt-jackson,代碼行數:34,代碼來源:BeanProcessor.java

示例4: jsonRedisSerializer

import com.fasterxml.jackson.annotation.JsonTypeInfo.As; //導入依賴的package包/類
private Jackson2JsonRedisSerializer jsonRedisSerializer(JavaType javaType)
{
    Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(javaType);
    ObjectMapper mapper = new ObjectMapper();
    mapper.enableDefaultTyping();
	mapper.enableDefaultTyping(DefaultTyping.NON_FINAL, As.PROPERTY);

	mapper.findAndRegisterModules();
    mapper.registerModule(new Jackson2HalModule());
    mapper.setHandlerInstantiator(new Jackson2HalModule.HalHandlerInstantiator(new DefaultRelProvider(), null, null));        
    jackson2JsonRedisSerializer.setObjectMapper(mapper);        
    return jackson2JsonRedisSerializer;
}
 
開發者ID:Azure,項目名稱:CityPower-Build-Sample,代碼行數:14,代碼來源:CacheConfig.java

示例5: inclusion

import com.fasterxml.jackson.annotation.JsonTypeInfo.As; //導入依賴的package包/類
public StdTypeResolverBuilder inclusion(JsonTypeInfo.As paramAs)
{
  if (paramAs == null)
    throw new IllegalArgumentException("includeAs can not be null");
  this._includeAs = paramAs;
  return this;
}
 
開發者ID:mmmsplay10,項目名稱:QuizUpWinner,代碼行數:8,代碼來源:StdTypeResolverBuilder.java

示例6: _findTypeResolver

import com.fasterxml.jackson.annotation.JsonTypeInfo.As; //導入依賴的package包/類
protected TypeResolverBuilder<?> _findTypeResolver(MapperConfig<?> paramMapperConfig, Annotated paramAnnotated, JavaType paramJavaType)
{
  JsonTypeInfo localJsonTypeInfo = (JsonTypeInfo)paramAnnotated.getAnnotation(JsonTypeInfo.class);
  JsonTypeResolver localJsonTypeResolver = (JsonTypeResolver)paramAnnotated.getAnnotation(JsonTypeResolver.class);
  Object localObject;
  if (localJsonTypeResolver != null)
  {
    if (localJsonTypeInfo == null)
      return null;
    localObject = paramMapperConfig.typeResolverBuilderInstance(paramAnnotated, localJsonTypeResolver.value());
  }
  else
  {
    if (localJsonTypeInfo == null)
      return null;
    if (localJsonTypeInfo.use() == JsonTypeInfo.Id.NONE)
      return _constructNoTypeResolverBuilder();
    localObject = _constructStdTypeResolverBuilder();
  }
  JsonTypeIdResolver localJsonTypeIdResolver = (JsonTypeIdResolver)paramAnnotated.getAnnotation(JsonTypeIdResolver.class);
  TypeIdResolver localTypeIdResolver1;
  if (localJsonTypeIdResolver == null)
    localTypeIdResolver1 = null;
  else
    localTypeIdResolver1 = paramMapperConfig.typeIdResolverInstance(paramAnnotated, localJsonTypeIdResolver.value());
  TypeIdResolver localTypeIdResolver2 = localTypeIdResolver1;
  if (localTypeIdResolver1 != null)
    localTypeIdResolver2.init(paramJavaType);
  TypeResolverBuilder localTypeResolverBuilder1 = ((TypeResolverBuilder)localObject).init(localJsonTypeInfo.use(), localTypeIdResolver2);
  JsonTypeInfo.As localAs1 = localJsonTypeInfo.include();
  JsonTypeInfo.As localAs2 = localAs1;
  if ((localAs1 == JsonTypeInfo.As.EXTERNAL_PROPERTY) && ((paramAnnotated instanceof AnnotatedClass)))
    localAs2 = JsonTypeInfo.As.PROPERTY;
  TypeResolverBuilder localTypeResolverBuilder2 = localTypeResolverBuilder1.inclusion(localAs2).typeProperty(localJsonTypeInfo.property());
  Class localClass = localJsonTypeInfo.defaultImpl();
  if (localClass != JsonTypeInfo.None.class)
    localTypeResolverBuilder2 = localTypeResolverBuilder2.defaultImpl(localClass);
  return localTypeResolverBuilder2.typeIdVisibility(localJsonTypeInfo.visible());
}
 
開發者ID:mmmsplay10,項目名稱:QuizUpWinner,代碼行數:40,代碼來源:JacksonAnnotationIntrospector.java

示例7: JsonObjectMapper

import com.fasterxml.jackson.annotation.JsonTypeInfo.As; //導入依賴的package包/類
public JsonObjectMapper() {
    registerModule(module);

    configure(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS, true);
    configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    enableDefaultTyping(DefaultTyping.NON_FINAL, As.WRAPPER_OBJECT);

    typer = new ClassAliasTypeResolverBuilder(DefaultTyping.NON_FINAL);
    setDefaultTyping(typer.inclusion(As.WRAPPER_OBJECT));
}
 
開發者ID:ragnor,項目名稱:simple-spring-memcached,代碼行數:11,代碼來源:JsonObjectMapper.java

示例8: processType

import com.fasterxml.jackson.annotation.JsonTypeInfo.As; //導入依賴的package包/類
/**
 * <p>processType</p>
 *
 * @param logger a {@link com.google.gwt.core.ext.TreeLogger} object.
 * @param typeOracle a {@link com.github.nmorel.gwtjackson.rebind.JacksonTypeOracle} object.
 * @param configuration a {@link com.github.nmorel.gwtjackson.rebind.RebindConfiguration} object.
 * @param typeOracle a {@link com.github.nmorel.gwtjackson.rebind.JacksonTypeOracle} object.
 * @param type a {@link com.google.gwt.core.ext.typeinfo.JClassType} object.
 * @param jsonTypeInfo a {@link com.google.gwt.thirdparty.guava.common.base.Optional} object.
 * @param propertySubTypes a {@link com.google.gwt.thirdparty.guava.common.base.Optional} object.
 * @return a {@link com.google.gwt.thirdparty.guava.common.base.Optional} object.
 * @throws com.google.gwt.core.ext.UnableToCompleteException if any.
 */
public static Optional<BeanTypeInfo> processType( TreeLogger logger, JacksonTypeOracle typeOracle, RebindConfiguration configuration,
                                                  JClassType type, Optional<JsonTypeInfo> jsonTypeInfo, Optional<JsonSubTypes>
        propertySubTypes ) throws UnableToCompleteException {

    if ( !jsonTypeInfo.isPresent() ) {
        jsonTypeInfo = findFirstEncounteredAnnotationsOnAllHierarchy( configuration, type, JsonTypeInfo.class );
        if ( !jsonTypeInfo.isPresent() ) {
            return Optional.absent();
        }
    }

    Id use = jsonTypeInfo.get().use();
    As include = jsonTypeInfo.get().include();
    String propertyName = jsonTypeInfo.get().property().isEmpty() ? jsonTypeInfo.get().use().getDefaultPropertyName() : jsonTypeInfo
            .get().property();

    Optional<JsonSubTypes> typeSubTypes = findFirstEncounteredAnnotationsOnAllHierarchy( configuration, type, JsonSubTypes.class );

    // TODO we could do better, we actually extract metadata twice for a lot of classes
    ImmutableMap<JClassType, String> classToSerializationMetadata = extractMetadata( logger, configuration, type, jsonTypeInfo,
            propertySubTypes, typeSubTypes, CreatorUtils
                    .filterSubtypesForSerialization( logger, configuration, type ) );
    ImmutableMap<JClassType, String> classToDeserializationMetadata = extractMetadata( logger, configuration, type, jsonTypeInfo,
            propertySubTypes, typeSubTypes, CreatorUtils
                    .filterSubtypesForDeserialization( logger, configuration, type ) );

    return Optional.of(
            new BeanTypeInfo( use, include, propertyName, classToSerializationMetadata, classToDeserializationMetadata ) );
}
 
開發者ID:nmorel,項目名稱:gwt-jackson,代碼行數:43,代碼來源:BeanProcessor.java

示例9: BeanTypeInfo

import com.fasterxml.jackson.annotation.JsonTypeInfo.As; //導入依賴的package包/類
BeanTypeInfo( Id use, As include, String propertyName, ImmutableMap<JClassType, String> mapTypeToSerializationMetadata,
              ImmutableMap<JClassType, String> mapTypeToDeserializationMetadata ) {
    this.use = use;
    this.include = include;
    this.propertyName = propertyName;
    this.mapTypeToSerializationMetadata = mapTypeToSerializationMetadata;
    this.mapTypeToDeserializationMetadata = mapTypeToDeserializationMetadata;
}
 
開發者ID:nmorel,項目名稱:gwt-jackson,代碼行數:9,代碼來源:BeanTypeInfo.java

示例10: getQuery

import com.fasterxml.jackson.annotation.JsonTypeInfo.As; //導入依賴的package包/類
@JsonTypeInfo(use = Id.NAME, include = As.EXISTING_PROPERTY)
public AntiochQuery getQuery() {
  return query;
}
 
開發者ID:HuygensING,項目名稱:antioch,代碼行數:5,代碼來源:SearchResult.java

示例11: getTypeInclusion

import com.fasterxml.jackson.annotation.JsonTypeInfo.As; //導入依賴的package包/類
public JsonTypeInfo.As getTypeInclusion()
{
  return JsonTypeInfo.As.PROPERTY;
}
 
開發者ID:mmmsplay10,項目名稱:QuizUpWinner,代碼行數:5,代碼來源:AsPropertyTypeDeserializer.java

示例12: getTypeInclusion

import com.fasterxml.jackson.annotation.JsonTypeInfo.As; //導入依賴的package包/類
public JsonTypeInfo.As getTypeInclusion()
{
  return JsonTypeInfo.As.WRAPPER_ARRAY;
}
 
開發者ID:mmmsplay10,項目名稱:QuizUpWinner,代碼行數:5,代碼來源:AsArrayTypeDeserializer.java

示例13: getTypeInclusion

import com.fasterxml.jackson.annotation.JsonTypeInfo.As; //導入依賴的package包/類
public JsonTypeInfo.As getTypeInclusion()
{
  return JsonTypeInfo.As.WRAPPER_OBJECT;
}
 
開發者ID:mmmsplay10,項目名稱:QuizUpWinner,代碼行數:5,代碼來源:AsWrapperTypeDeserializer.java

示例14: getTypeInclusion

import com.fasterxml.jackson.annotation.JsonTypeInfo.As; //導入依賴的package包/類
public JsonTypeInfo.As getTypeInclusion()
{
  return JsonTypeInfo.As.EXTERNAL_PROPERTY;
}
 
開發者ID:mmmsplay10,項目名稱:QuizUpWinner,代碼行數:5,代碼來源:AsExternalTypeDeserializer.java

示例15: getID

import com.fasterxml.jackson.annotation.JsonTypeInfo.As; //導入依賴的package包/類
/** @return the identifier */
@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=As.PROPERTY, property="class")
ID getID();
 
開發者ID:krevelen,項目名稱:coala,代碼行數:4,代碼來源:Identifiable.java


注:本文中的com.fasterxml.jackson.annotation.JsonTypeInfo.As類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。