本文整理汇总了Java中com.fasterxml.jackson.annotation.JsonTypeName.value方法的典型用法代码示例。如果您正苦于以下问题:Java JsonTypeName.value方法的具体用法?Java JsonTypeName.value怎么用?Java JsonTypeName.value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.annotation.JsonTypeName
的用法示例。
在下文中一共展示了JsonTypeName.value方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: 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));
}
}
}
}
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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();
}
示例7: 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();
}
示例8: 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();
}
示例9: 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;
}
示例10: getName
import com.fasterxml.jackson.annotation.JsonTypeName; //导入方法依赖的package包/类
public String getName(JavaType type) {
Class<?> rawClass = type.getRawClass();
JsonTypeName typeName = rawClass.getAnnotation(JsonTypeName.class);
if (typeName != null) {
return typeName.value();
}
else {
return getName(rawClass);
}
}
示例11: getInheritance
import com.fasterxml.jackson.annotation.JsonTypeName; //导入方法依赖的package包/类
private void getInheritance(ClassInformation information, ReflectClass<?> cls) {
JsonTypeName typeName = cls.getAnnotation(JsonTypeName.class);
if (information.typeName == null) {
information.typeName = "";
}
if (typeName != null) {
information.typeName = typeName.value();
}
if (information.typeName.isEmpty()) {
information.typeName = getUnqualifiedName(cls.getName());
}
JsonTypeInfo typeInfo = cls.getAnnotation(JsonTypeInfo.class);
if (typeInfo != null) {
String defaultProperty = "";
switch (typeInfo.use()) {
case CLASS:
information.inheritance.value = InheritanceValue.CLASS;
defaultProperty = "@class";
break;
case MINIMAL_CLASS:
information.inheritance.value = InheritanceValue.MINIMAL_CLASS;
defaultProperty = "@c";
break;
case NAME:
information.inheritance.value = InheritanceValue.NAME;
defaultProperty = "@type";
break;
case NONE:
information.inheritance.value = InheritanceValue.NONE;
break;
default:
diagnostics.warning(null, "{{t0}}: unsupported value " + typeInfo.use() + " in {{t1}}",
cls, JsonTypeInfo.Id.class);
break;
}
if (information.inheritance.value != InheritanceValue.NONE) {
switch (typeInfo.include()) {
case PROPERTY:
information.inheritance.key = InheritanceKey.PROPERTY;
break;
case WRAPPER_ARRAY:
information.inheritance.key = InheritanceKey.WRAPPER_ARRAY;
break;
case WRAPPER_OBJECT:
information.inheritance.key = InheritanceKey.WRAPPER_OBJECT;
break;
default:
diagnostics.warning(null, "{{t0}}: unsupported value " + typeInfo.include()
+ " in {{t1}}", cls, JsonTypeInfo.As.class);
break;
}
}
if (information.inheritance.key == InheritanceKey.PROPERTY) {
String property = typeInfo.property();
if (property.isEmpty()) {
property = defaultProperty;
}
information.inheritance.propertyName = property;
}
}
}