当前位置: 首页>>代码示例>>Java>>正文


Java JsonTypeName类代码示例

本文整理汇总了Java中com.fasterxml.jackson.annotation.JsonTypeName的典型用法代码示例。如果您正苦于以下问题:Java JsonTypeName类的具体用法?Java JsonTypeName怎么用?Java JsonTypeName使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JsonTypeName类属于com.fasterxml.jackson.annotation包,在下文中一共展示了JsonTypeName类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: FormatPluginOptionsDescriptor

import com.fasterxml.jackson.annotation.JsonTypeName; //导入依赖的package包/类
/**
 * Uses reflection to extract options based on the fields of the provided config class
 * ("List extensions" field is ignored, pending removal, Char is turned into String)
 * The class must be annotated with {@code @JsonTypeName("type name")}
 * @param pluginConfigClass the config class we want to extract options from through reflection
 */
FormatPluginOptionsDescriptor(Class<? extends FormatPluginConfig> pluginConfigClass) {
  this.pluginConfigClass = pluginConfigClass;
  Map<String, TableParamDef> paramsByName = new LinkedHashMap<>();
  Field[] fields = pluginConfigClass.getDeclaredFields();
  // @JsonTypeName("text")
  JsonTypeName annotation = pluginConfigClass.getAnnotation(JsonTypeName.class);
  this.typeName = annotation != null ? annotation.value() : null;
  if (this.typeName != null) {
    paramsByName.put("type", new TableParamDef("type", String.class));
  }
  for (Field field : fields) {
    if (Modifier.isStatic(field.getModifiers())
        // we want to deprecate this field
        || (field.getName().equals("extensions") && field.getType() == List.class)) {
      continue;
    }
    Class<?> fieldType = field.getType();
    if (fieldType == char.class) {
      // calcite does not like char type. Just use String and enforce later that length == 1
      fieldType = String.class;
    }
    paramsByName.put(field.getName(), new TableParamDef(field.getName(), fieldType).optional());
  }
  this.functionParamsByName = unmodifiableMap(paramsByName);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:32,代码来源:FormatPluginOptionsDescriptor.java

示例2: assignTypeNameIfNecessary

import com.fasterxml.jackson.annotation.JsonTypeName; //导入依赖的package包/类
public void assignTypeNameIfNecessary(ClassesMapping classesMapping, ClassMappingInternal<Object> currentClassMapping) {
    if (!currentClassMapping.hasAnnotation(JsonTypeName.class)) {
        typesWithPolymorphism.stream()
                .filter(typeWithPolymorphism -> typeWithPolymorphism.isAssignableFrom(currentClassMapping.getType()))
                .findFirst()
                .ifPresent(typeWithPolymorphism -> classesMapping.getOpt(typeWithPolymorphism)
                        .ifPresent(classMapping -> classMapping.getAnnotationOpt(JsonSubTypes.class)
                                .ifPresent((jsonSubTypes) -> Arrays.asList(jsonSubTypes.value()).stream()
                                        .filter(subtype -> subtype.value().equals(classMapping.getType()))
                                        .findFirst()
                                        .map(JsonSubTypes.Type::name)
                                        .ifPresent(classMapping::typeName)
                                )
                        )
                );
    }
}
 
开发者ID:mrenou,项目名称:jacksonatic,代码行数:18,代码来源:TypeNameAutoAssigner.java

示例3: testRoot

import com.fasterxml.jackson.annotation.JsonTypeName; //导入依赖的package包/类
protected void testRoot() {
    // while boundaries are compiler-checked, let's still verify superclass, as generics in Java are easy to bypass
    assertTrue("Invalid root type: " + expectedRoot, PolymorphicConfiguration.class.isAssignableFrom(expectedRoot));

    JsonTypeInfo typeInfo = expectedRoot.getAnnotation(JsonTypeInfo.class);

    //  TODO: test "property" and "use" values of the annotation
    assertNotNull("Root is not annotated with @JsonTypeInfo", typeInfo);
    if (expectedDefault != null) {
        assertTrue("Default type is not specified on root. Expected: " + expectedDefault.getName(),
                hasDefault(typeInfo));
        assertEquals("Expected and actual default types are not the same", expectedDefault,
                typeInfo.defaultImpl());
    } else {
        assertFalse("Expected no default type, but @JsonTypeInfo sets it to " + typeInfo.defaultImpl().getName() + ".",
                hasDefault(typeInfo));
    }

    if (isConcrete(expectedRoot)) {
        JsonTypeName typeName = expectedRoot.getAnnotation(JsonTypeName.class);
        assertNotNull("Concrete root configuration type must be annotated with @JsonTypeName: " + expectedRoot.getName());
    }
}
 
开发者ID:bootique,项目名称:bootique,代码行数:24,代码来源:PolymorphicConfigurationChecker.java

示例4: init

import com.fasterxml.jackson.annotation.JsonTypeName; //导入依赖的package包/类
public void init(JavaType baseType) {
    this.baseType = baseType;
    ArrayList<Class<?>> classes = new ArrayList<Class<?>>();
    classes.add(baseType.getRawClass());
    classes.addAll(Arrays.asList(DtoModules.extensionClasses()));
    for ( Class<?> c : classes) {
        if( baseType.getRawClass().isAssignableFrom(c) ) {
            JsonTypeName jsonAnnoation = c.getAnnotation(JsonTypeName.class);
            if(jsonAnnoation!=null && jsonAnnoation.value()!=null) {
                typeToId.put(c, jsonAnnoation.value());
                idToType.put(jsonAnnoation.value(), TypeFactory.defaultInstance().constructSpecializedType(baseType, c));
                idToType.put(c.getName(), TypeFactory.defaultInstance().constructSpecializedType(baseType, c));
            } else {
                XmlRootElement xmlAnnoation = c.getAnnotation(XmlRootElement.class);
                if(xmlAnnoation!=null && xmlAnnoation.name()!=null) {
                    typeToId.put(c, xmlAnnoation.name());
                    idToType.put(xmlAnnoation.name(), TypeFactory.defaultInstance().constructSpecializedType(baseType, c));
                    idToType.put(c.getName(), TypeFactory.defaultInstance().constructSpecializedType(baseType, c));
                }
            }
        }
    }
}
 
开发者ID:christian-posta,项目名称:activemq-apollo-java-port,代码行数:24,代码来源:ApolloTypeIdResolver.java

示例5: runnerFor

import com.fasterxml.jackson.annotation.JsonTypeName; //导入依赖的package包/类
@Override
public <J> Runnable runnerFor(J job) {
   Assert.notNull(job, "Pre-condition violated: job != null.");

   JsonTypeName type = job.getClass().getAnnotation(JsonTypeName.class);
   Assert.notNull(type, "Pre-condition violated: Job has a @JsonTypeName.");
   String jsonType = type.value();
   if (!StringUtils.hasLength(jsonType)) {
      // If the type is not specified in the annotation, use the simple class name as documented.
      jsonType = job.getClass().getSimpleName();
   }

   // Check for bean existence and that bean is a prototype.
   // Beans have to be prototypes, because they are configured with the job vars below.
   if (!applicationContext.isPrototype(jsonType)) {
      throw new IllegalArgumentException(String.format(
            "Job runners have to be prototypes, but job runner %s is none.", jsonType));
   }

   Object runner = applicationContext.getBean(jsonType, job);
   if (!(runner instanceof Runnable)) {
      throw new IllegalArgumentException(String.format(
            "Job runners need to be Runnable, but job runner %s (%s) is not.",
            jsonType, runner.getClass().getName()));
   }

   return (Runnable) runner;
}
 
开发者ID:shopping24,项目名称:redjob,代码行数:29,代码来源:JsonTypeJobRunnerFactory.java

示例6: test

import com.fasterxml.jackson.annotation.JsonTypeName; //导入依赖的package包/类
@Test
public void test() {
  DrillConfig config = DrillConfig.create();
  ScanResult scanResult = RunTimeScan.fromPrescan(config);
  FormatPluginOptionExtractor e = new FormatPluginOptionExtractor(scanResult);
  Collection<FormatPluginOptionsDescriptor> options = e.getOptions();
  for (FormatPluginOptionsDescriptor d : options) {
    assertEquals(d.pluginConfigClass.getAnnotation(JsonTypeName.class).value(), d.typeName);
    switch (d.typeName) {
      case "text":
        assertEquals(TextFormatConfig.class, d.pluginConfigClass);
        assertEquals(
            "(type: String, lineDelimiter: String, fieldDelimiter: String, quote: String, escape: String, comment: String, skipFirstLine: boolean, extractHeader: boolean)",
            d.presentParams()
        );
        break;
      case "named":
        assertEquals(NamedFormatPluginConfig.class, d.pluginConfigClass);
        assertEquals("(type: String, name: String)", d.presentParams());
        break;
      case "parquet":
        assertEquals(d.typeName, "(type: String, autoCorrectCorruptDates: boolean)", d.presentParams());
        break;
      case "json":
      case "sequencefile":
      case "pcap":
      case "avro":
        assertEquals(d.typeName, "(type: String)", d.presentParams());
        break;
      case "httpd":
        assertEquals("(type: String, logFormat: String, timestampFormat: String)", d.presentParams());
        break;
      default:
        fail("add validation for format plugin type " + d.typeName);
    }
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:38,代码来源:TestFormatPluginOptionExtractor.java

示例7: getStructureElementIdentifier

import com.fasterxml.jackson.annotation.JsonTypeName; //导入依赖的package包/类
/**
 * Returns the identifier of a given class
 * 
 * @param c
 *            the class whose identifier is requested
 * @return the class identifier
 */
public static String getStructureElementIdentifier(
		Class<? extends StructureElement> c) {
	String structureElementAbbreviation;
	if (c.isAnnotationPresent(JsonTypeName.class)) {
		JsonTypeName info = c.getAnnotation(JsonTypeName.class);
		structureElementAbbreviation = info.value();

	} else {
		structureElementAbbreviation = c.getSimpleName().toUpperCase();
	}
	return structureElementAbbreviation;
}
 
开发者ID:SAG-KeLP,项目名称:kelp-additional-kernels,代码行数:20,代码来源:StructureElementFactory.java

示例8: testNonRoot

import com.fasterxml.jackson.annotation.JsonTypeName; //导入依赖的package包/类
protected void testNonRoot(Class<? extends T> t) {
    // while boundaries are compiler-checked, let's still verify superclass, as generics in Java are easy to bypass
    assertTrue("Invalid type " + t.getName() + ". Must be a subclass of root type " + expectedRoot.getName(),
            expectedRoot.isAssignableFrom(t));

    assertTrue("Non-root configuration type must not be abstract: " + t.getName(), isConcrete(t));

    // this check would prevent matching subclasses by class, but we discourage that anyways.. (otherwise FQN
    // would have to be used in YAML)

    JsonTypeName typeName = t.getAnnotation(JsonTypeName.class);
    assertNotNull("Non-root configuration type must be annotated with @JsonTypeName: " + t.getName());
}
 
开发者ID:bootique,项目名称:bootique,代码行数:14,代码来源:PolymorphicConfigurationChecker.java

示例9: extractTypeLabel

import com.fasterxml.jackson.annotation.JsonTypeName; //导入依赖的package包/类
protected String extractTypeLabel(Class<?> type) {
    // TODO: get rid of Jackson annotations dependency .. devise our own that reflect Bootique style of config factory
    // subclassing...

    JsonTypeName typeName = type.getAnnotation(JsonTypeName.class);
    return typeName != null ? typeName.value() : null;
}
 
开发者ID:bootique,项目名称:bootique,代码行数:8,代码来源:ConfigMetadataCompiler.java

示例10: buildTypeId

import com.fasterxml.jackson.annotation.JsonTypeName; //导入依赖的package包/类
private <T extends Filter> String buildTypeId(final String id, final Class<T> type) {
    final JsonTypeName annotation = type.getAnnotation(JsonTypeName.class);

    if (annotation == null) {
        return id;
    }

    return annotation.value();
}
 
开发者ID:spotify,项目名称:heroic,代码行数:10,代码来源:FilterRegistry.java

示例11: getTypeLabel

import com.fasterxml.jackson.annotation.JsonTypeName; //导入依赖的package包/类
private String getTypeLabel(Class<? extends ManagedDataSourceFactory> factoryType) {

        // TODO: see TODO in ConfigMetadataCompiler ... at least maybe create a public API for this in Bootique to
        // avoid parsing annotations inside the modules...
        JsonTypeName typeName = factoryType.getAnnotation(JsonTypeName.class);

        if (typeName == null) {
            throw new BootiqueException(1, "Invalid ManagedDataSourceFactory:  "
                    + factoryType.getName()
                    + ". Not annotated with @JsonTypeName.");
        }

        return typeName.value();
    }
 
开发者ID:bootique,项目名称:bootique-jdbc,代码行数:15,代码来源:ManagedDataSourceFactoryProxy.java

示例12: findTypeName

import com.fasterxml.jackson.annotation.JsonTypeName; //导入依赖的package包/类
public String findTypeName(AnnotatedClass paramAnnotatedClass)
{
  JsonTypeName localJsonTypeName = (JsonTypeName)paramAnnotatedClass.getAnnotation(JsonTypeName.class);
  if (localJsonTypeName == null)
    return null;
  return localJsonTypeName.value();
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:8,代码来源:JacksonAnnotationIntrospector.java

示例13: getTypeName

import com.fasterxml.jackson.annotation.JsonTypeName; //导入依赖的package包/类
private String getTypeName(JsonTypeInfo parentJsonTypeInfo, final Class<?> cls) {
    // Id.CLASS
    if (parentJsonTypeInfo.use() == JsonTypeInfo.Id.CLASS) {
        return cls.getName();
    }
    // find @JsonTypeName recursively
    final JsonTypeName jsonTypeName = getAnnotationRecursive(cls, JsonTypeName.class);
    if (jsonTypeName != null && !jsonTypeName.value().isEmpty()) {
        return jsonTypeName.value();
    }
    // find @JsonSubTypes.Type recursively
    final JsonSubTypes jsonSubTypes = getAnnotationRecursive(cls, JsonSubTypes.class, new Predicate<JsonSubTypes>() {
        @Override
        public boolean test(JsonSubTypes types) {
            return getJsonSubTypeForClass(types, cls) != null;
        }
    });
    if (jsonSubTypes != null) {
        final JsonSubTypes.Type jsonSubType = getJsonSubTypeForClass(jsonSubTypes, cls);
        if (!jsonSubType.name().isEmpty()) {
            return jsonSubType.name();
        }
    }
    // use simplified class name if it's not an interface or abstract
    if(!cls.isInterface() && !Modifier.isAbstract(cls.getModifiers())) {
        return cls.getName().substring(cls.getName().lastIndexOf(".") + 1);
    }
    return null;
}
 
开发者ID:vojtechhabarta,项目名称:typescript-generator,代码行数:30,代码来源:Jackson2Parser.java

示例14: serialize

import com.fasterxml.jackson.annotation.JsonTypeName; //导入依赖的package包/类
@Override
public void serialize(Wrapper value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    jgen.writeStartObject();

    String name = value.getElement().getClass().getAnnotation(JsonTypeName.class).value();
    jgen.writeFieldName(name);

    provider.defaultSerializeValue(value.getElement(), jgen);
    jgen.writeEndObject();

}
 
开发者ID:felipesere,项目名称:collection-json-parser,代码行数:12,代码来源:WrapperSerializer.java

示例15: extractTypeMetadata

import com.fasterxml.jackson.annotation.JsonTypeName; //导入依赖的package包/类
private static String extractTypeMetadata( TreeLogger logger, RebindConfiguration configuration, JClassType baseType, JClassType
        subtype, JsonTypeInfo typeInfo, Optional<JsonSubTypes> propertySubTypes, Optional<JsonSubTypes> baseSubTypes,
                                           ImmutableList<JClassType> allSubtypes ) throws UnableToCompleteException {
    switch ( typeInfo.use() ) {
        case NAME:
            // we first look the name on JsonSubTypes annotations. Top ones override the bottom ones.
            String name = findNameOnJsonSubTypes( baseType, subtype, allSubtypes, propertySubTypes, baseSubTypes );
            if ( null != name && !"".equals( name ) ) {
                return name;
            }

            // we look if the name is defined on the type with JsonTypeName
            Optional<JsonTypeName> typeName = findFirstEncounteredAnnotationsOnAllHierarchy( configuration, subtype, JsonTypeName
                    .class );
            if ( typeName.isPresent() && !Strings.isNullOrEmpty( typeName.get().value() ) ) {
                return typeName.get().value();
            }

            // we use the default name (ie simple name of the class)
            String simpleBinaryName = subtype.getQualifiedBinaryName();
            int indexLastDot = simpleBinaryName.lastIndexOf( '.' );
            if ( indexLastDot != -1 ) {
                simpleBinaryName = simpleBinaryName.substring( indexLastDot + 1 );
            }
            return simpleBinaryName;
        case MINIMAL_CLASS:
            if ( !baseType.getPackage().isDefault() ) {
                String basePackage = baseType.getPackage().getName();
                if ( subtype.getQualifiedBinaryName().startsWith( basePackage + "." ) ) {
                    return subtype.getQualifiedBinaryName().substring( basePackage.length() );
                }
            }
        case CLASS:
            return subtype.getQualifiedBinaryName();
        default:
            logger.log( TreeLogger.Type.ERROR, "JsonTypeInfo.Id." + typeInfo.use() + " is not supported" );
            throw new UnableToCompleteException();
    }
}
 
开发者ID:nmorel,项目名称:gwt-jackson,代码行数:40,代码来源:BeanProcessor.java


注:本文中的com.fasterxml.jackson.annotation.JsonTypeName类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。