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


Java JsonTypeName.value方法代碼示例

本文整理匯總了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);
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:32,代碼來源:FormatPluginOptionsDescriptor.java

示例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));
                }
            }
        }
    }
}
 
開發者ID:christian-posta,項目名稱:activemq-apollo-java-port,代碼行數:24,代碼來源:ApolloTypeIdResolver.java

示例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;
}
 
開發者ID:shopping24,項目名稱:redjob,代碼行數:29,代碼來源:JsonTypeJobRunnerFactory.java

示例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;
}
 
開發者ID:SAG-KeLP,項目名稱:kelp-additional-kernels,代碼行數:20,代碼來源:StructureElementFactory.java

示例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;
}
 
開發者ID:bootique,項目名稱:bootique,代碼行數:8,代碼來源:ConfigMetadataCompiler.java

示例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();
}
 
開發者ID:spotify,項目名稱:heroic,代碼行數:10,代碼來源:FilterRegistry.java

示例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();
    }
 
開發者ID:bootique,項目名稱:bootique-jdbc,代碼行數:15,代碼來源:ManagedDataSourceFactoryProxy.java

示例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();
}
 
開發者ID:mmmsplay10,項目名稱:QuizUpWinner,代碼行數:8,代碼來源:JacksonAnnotationIntrospector.java

示例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;
}
 
開發者ID:vojtechhabarta,項目名稱:typescript-generator,代碼行數:30,代碼來源:Jackson2Parser.java

示例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);
	}
}
 
開發者ID:raphaeljolivet,項目名稱:java2typescript,代碼行數:11,代碼來源:SimpleJacksonTSTypeNamingStrategy.java

示例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;
        }
    }
}
 
開發者ID:konsoletyper,項目名稱:teavm-flavour,代碼行數:65,代碼來源:ClassInformationProvider.java


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