/** * @return A converter that converts bytebufs to strings */ @Singleton @Bean TypeConverter<ByteBuf, CharSequence> byteBufCharSequenceTypeConverter() { return (object, targetType, context) -> Optional.of(object.toString(context.getCharset())); }
/** * @return A converter that converts composite bytebufs to strings */ @Singleton @Bean TypeConverter<CompositeByteBuf, CharSequence> compositeByteBufCharSequenceTypeConverter() { return (object, targetType, context) -> Optional.of(object.toString(context.getCharset())); }
/** * Augment this context with annotation metadata. * * @param annotationMetadata The annotation metadata * @return The conversion context */ @SuppressWarnings("unchecked") default ArgumentConversionContext<T> with(AnnotationMetadata annotationMetadata) { ConversionContext thisContext = this; return new DefaultArgumentConversionContext(getArgument(), thisContext.getLocale(), thisContext.getCharset()) { @Override public AnnotationMetadata getAnnotationMetadata() { return annotationMetadata; } }; } }
return new DefaultArgumentConversionContext(argument, thisContext.getLocale(), thisContext.getCharset()) { @Override public <T extends Annotation> T synthesize(Class<T> annotationClass) {
addConverter(CharSequence.class, byte[].class, (object, targetType, context) -> Optional.of(object.toString().getBytes(context.getCharset()))); addConverter(Integer.class, byte[].class, (object, targetType, context) -> Optional.of(ByteBuffer.allocate(Integer.BYTES).putInt(object).array())); addConverter(Character.class, byte[].class, (object, targetType, context) -> Optional.of(ByteBuffer.allocate(Integer.BYTES).putChar(object).array()));