io.micronaut.context.ApplicationContext.getConversionService()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(2.2k)|赞(0)|评价(0)|浏览(135)

本文整理了Java中io.micronaut.context.ApplicationContext.getConversionService()方法的一些代码示例,展示了ApplicationContext.getConversionService()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ApplicationContext.getConversionService()方法的具体详情如下:
包路径:io.micronaut.context.ApplicationContext
类名称:ApplicationContext
方法名:getConversionService

ApplicationContext.getConversionService介绍

暂无

代码示例

代码示例来源:origin: micronaut-projects/micronaut-core

/**
 * Get.
 *
 * @param type type
 * @param <T> generic return type
 * @return Type
 */
public final <T> T get(Class<T> type) {
  if (ClassUtils.isJavaLangType(type)) {
    return applicationContext
      .getConversionService()
      .convert(data, type).orElseThrow(() -> newIllegalArgument(type, data));
  } else {
    MediaTypeCodecRegistry codecRegistry = applicationContext.getBean(MediaTypeCodecRegistry.class);
    return codecRegistry.findCodec(MediaType.APPLICATION_JSON_TYPE)
      .map(codec -> {
        if (data != null) {
          return codec.decode(type, data);
        } else {
          // try System.in
          return codec.decode(type, System.in);
        }
      })
      .orElseThrow(() -> newIllegalArgument(type, data));
  }
}

代码示例来源:origin: io.micronaut/micronaut-inject

private Optional resolveValue(
    ApplicationContext context,
    ArgumentConversionContext<?> argument,
    boolean hasValueAnnotation,
    String valString) {
  if (hasValueAnnotation) {
    return context.resolvePlaceholders(valString).flatMap(v ->
        context.getConversionService().convert(v, argument)
    );
  } else {
    Optional<?> value = context.getProperty(valString, argument);
    if (!value.isPresent() && isConfigurationProperties()) {
      String cliOption = resolveCliOption(argument.getArgument().getName());
      if (cliOption != null) {
        return context.getProperty(cliOption, argument);
      }
    }
    return value;
  }
}

代码示例来源:origin: io.micronaut/inject

private Optional resolveValue(
    ApplicationContext context,
    ArgumentConversionContext<?> argument,
    boolean hasValueAnnotation,
    String valString) {
  if (hasValueAnnotation) {
    return context.resolvePlaceholders(valString).flatMap(v ->
        context.getConversionService().convert(v, argument)
    );
  } else {
    Optional<?> value = context.getProperty(valString, argument);
    if (!value.isPresent() && isConfigurationProperties()) {
      String cliOption = resolveCliOption(argument.getArgument().getName());
      if (cliOption != null) {
        return context.getProperty(cliOption, argument);
      }
    }
    return value;
  }
}

相关文章