io.micronaut.core.bind.annotation.Bindable Java Examples

The following examples show how to use io.micronaut.core.bind.annotation.Bindable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConsumerRecordBinderRegistry.java    From micronaut-kafka with Apache License 2.0 6 votes vote down vote up
@Override
public <T> Optional<ArgumentBinder<T, ConsumerRecord<?, ?>>> findArgumentBinder(Argument<T> argument, ConsumerRecord<?, ?> source) {
    Optional<Class<? extends Annotation>> annotationType = argument.getAnnotationMetadata().getAnnotationTypeByStereotype(Bindable.class);
    if (annotationType.isPresent()) {
        @SuppressWarnings("unchecked") ConsumerRecordBinder<T> consumerRecordBinder =
                (ConsumerRecordBinder<T>) byAnnotation.get(annotationType.get());

        return Optional.ofNullable(consumerRecordBinder);
    } else {
        @SuppressWarnings("unchecked")
        ConsumerRecordBinder<T> binder = (ConsumerRecordBinder<T>) byType.get(argument.typeHashCode());
        if (binder != null) {
            return Optional.of(binder);
        } else {
            return Optional.of(new KafkaDefaultBinder<>());
        }
    }
}
 
Example #2
Source File: JasyncPoolConfiguration.java    From micronaut-sql with Apache License 2.0 5 votes vote down vote up
/**
 * Default constructor.
 * @param mode The mode
 * @param rootCert The cert
 */
@ConfigurationInject
public JasyncSslConfiguration(
        @Bindable(defaultValue = "Disable")
        SSLConfiguration.Mode mode,
        @Nullable String rootCert) {
    this.mode = mode;
    this.rootCert = rootCert != null ? new File(rootCert) : null;
}
 
Example #3
Source File: KafkaConsumerProcessor.java    From micronaut-kafka with Apache License 2.0 5 votes vote down vote up
private Argument findBodyArgument(ExecutableMethod<?, ?> method) {
    return Arrays.stream(method.getArguments())
            .filter(arg -> arg.getType() == ConsumerRecord.class || arg.getAnnotationMetadata().hasAnnotation(Body.class))
            .findFirst()
            .orElseGet(() ->
                    Arrays.stream(method.getArguments())
                            .filter(arg -> !arg.getAnnotationMetadata().hasStereotype(Bindable.class))
                            .findFirst()
                            .orElse(null)
            );
}
 
Example #4
Source File: RequestBodyAnnotationMapping.java    From micronaut-spring with Apache License 2.0 5 votes vote down vote up
@Override
protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    List<AnnotationValue<?>> mappedAnnotations = new ArrayList<>();
    final boolean required = annotation.get("required", boolean.class).orElse(true);
    final AnnotationValueBuilder<?> builder = AnnotationValue.builder(Body.class);
    final AnnotationValueBuilder<Bindable> bindableBuilder = AnnotationValue.builder(Bindable.class);
    mappedAnnotations.add(builder.build());
    mappedAnnotations.add(bindableBuilder.build());
    if (!required) {
        mappedAnnotations.add(AnnotationValue.builder(Nullable.class).build());
    }
    return mappedAnnotations;
}
 
Example #5
Source File: WebBindAnnotationMapper.java    From micronaut-spring with Apache License 2.0 5 votes vote down vote up
@Override
protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    List<AnnotationValue<?>> mappedAnnotations = new ArrayList<>();

    final String name = annotation.getValue(String.class).orElseGet(() -> annotation.get("name", String.class).orElse(null));
    final String defaultValue = annotation.get("defaultValue", String.class).orElse(null);
    final boolean required = annotation.get("required", boolean.class).orElse(true);

    final AnnotationValueBuilder<?> builder = AnnotationValue.builder(annotationType());
    final AnnotationValueBuilder<Bindable> bindableBuilder = AnnotationValue.builder(Bindable.class);
    if (StringUtils.isNotEmpty(name)) {
        builder.value(name);
        bindableBuilder.value(name);
    }
    if (StringUtils.isNotEmpty(defaultValue)) {
        builder.member("defaultValue", name);
        bindableBuilder.member("defaultValue", defaultValue);
    }

    mappedAnnotations.add(builder.build());
    mappedAnnotations.add(bindableBuilder.build());
    if (!required) {
        mappedAnnotations.add(AnnotationValue.builder(Nullable.class).build());
    }

    return mappedAnnotations;
}