Java Code Examples for io.micronaut.core.type.Argument#getName()

The following examples show how to use io.micronaut.core.type.Argument#getName() . 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: ProtobufferCodec.java    From micronaut-grpc with Apache License 2.0 6 votes vote down vote up
@Override
public <T> T decode(Argument<T> type, ByteBuffer<?> buffer) throws CodecException {
    try {
        if (type.getType() == byte[].class) {
            return (T) buffer.toByteArray();
        } else {
            Message.Builder builder = getBuilder(type)
                    .orElseThrow(() -> new CodecException("Unable to create builder"));
            if (type.hasTypeVariables()) {
                throw new IllegalStateException("Generic type arguments are not supported");
            } else {
                builder.mergeFrom(buffer.toByteArray(), extensionRegistry);
                return type.getType().cast(builder.build());
            }
        }
    } catch (Exception e) {
        throw new CodecException("Error decoding Protobuff bytes for type [" + type.getName() + "]: " + e.getMessage(), e);
    }
}
 
Example 2
Source File: ProtobufferCodec.java    From micronaut-grpc with Apache License 2.0 6 votes vote down vote up
@Override
public <T> T decode(Argument<T> type, byte[] bytes) throws CodecException {
    try {
        if (type.getType() == byte[].class) {
            return (T) bytes;
        } else {
            Message.Builder builder = getBuilder(type)
                    .orElseThrow(() -> new CodecException("Unable to create builder"));
            if (type.hasTypeVariables()) {
                throw new IllegalStateException("Generic type arguments are not supported");
            } else {
                builder.mergeFrom(bytes, extensionRegistry);
                return type.getType().cast(builder.build());
            }
        }
    } catch (Exception e) {
        throw new CodecException("Error decoding Protobuff bytes for type [" + type.getName() + "]: " + e.getMessage(), e);
    }
}
 
Example 3
Source File: SqlResultEntityTypeMapper.java    From micronaut-data with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public Object read(@NonNull RS resultSet, @NonNull Argument<?> argument) {
    RuntimePersistentProperty<R> property = entity.getPropertyByName(argument.getName());
    DataType dataType;
    String columnName;
    if (property == null) {
        dataType = argument.getAnnotationMetadata()
                .enumValue(TypeDef.class, "type", DataType.class)
                .orElseGet(() -> DataType.forType(argument.getType()));
        columnName = argument.getName();
    } else {
        dataType = property.getDataType();
        columnName = property.getPersistedName();
    }

    return resultReader.readDynamic(
            resultSet,
            columnName,
            dataType
    );
}
 
Example 4
Source File: ProtobufferCodec.java    From micronaut-grpc with Apache License 2.0 6 votes vote down vote up
@Override
public <T> T decode(Argument<T> type, ByteBuffer<?> buffer) throws CodecException {
    try {
        if (type.getType() == byte[].class) {
            return (T) buffer.toByteArray();
        } else {
            Message.Builder builder = getBuilder(type)
                    .orElseThrow(() -> new CodecException("Unable to create builder"));
            if (type.hasTypeVariables()) {
                throw new IllegalStateException("Generic type arguments are not supported");
            } else {
                builder.mergeFrom(buffer.toByteArray(), extensionRegistry);
                return type.getType().cast(builder.build());
            }
        }
    } catch (Exception e) {
        throw new CodecException("Error decoding Protobuff bytes for type [" + type.getName() + "]: " + e.getMessage(), e);
    }
}
 
Example 5
Source File: ProtobufferCodec.java    From micronaut-grpc with Apache License 2.0 6 votes vote down vote up
@Override
public <T> T decode(Argument<T> type, byte[] bytes) throws CodecException {
    try {
        if (type.getType() == byte[].class) {
            return (T) bytes;
        } else {
            Message.Builder builder = getBuilder(type)
                    .orElseThrow(() -> new CodecException("Unable to create builder"));
            if (type.hasTypeVariables()) {
                throw new IllegalStateException("Generic type arguments are not supported");
            } else {
                builder.mergeFrom(bytes, extensionRegistry);
                return type.getType().cast(builder.build());
            }
        }
    } catch (Exception e) {
        throw new CodecException("Error decoding Protobuff bytes for type [" + type.getName() + "]: " + e.getMessage(), e);
    }
}
 
Example 6
Source File: ProtobufferCodec.java    From micronaut-grpc with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T decode(Argument<T> type, InputStream inputStream) throws CodecException {
    try {
        Message.Builder builder = getBuilder(type)
                .orElseThrow(() -> new CodecException("Unable to create builder"));
        if (type.hasTypeVariables()) {
            throw new IllegalStateException("Generic type arguments are not supported");
        } else {
            builder.mergeFrom(inputStream, extensionRegistry);
            return type.getType().cast(builder.build());
        }
    } catch (Exception e) {
        throw new CodecException("Error decoding Protobuff stream for type [" + type.getName() + "]: " + e.getMessage(), e);
    }
}
 
Example 7
Source File: ProtobufferCodec.java    From micronaut-grpc with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T decode(Argument<T> type, InputStream inputStream) throws CodecException {
    try {
        Message.Builder builder = getBuilder(type)
                .orElseThrow(() -> new CodecException("Unable to create builder"));
        if (type.hasTypeVariables()) {
            throw new IllegalStateException("Generic type arguments are not supported");
        } else {
            builder.mergeFrom(inputStream, extensionRegistry);
            return type.getType().cast(builder.build());
        }
    } catch (Exception e) {
        throw new CodecException("Error decoding Protobuff stream for type [" + type.getName() + "]: " + e.getMessage(), e);
    }
}