Add support for Charset for property value code generation

Closes gh-29186
This commit is contained in:
Stephane Nicoll
2022-09-21 19:27:05 +02:00
parent 5192d99fa4
commit 84fd942712
2 changed files with 34 additions and 0 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.beans.factory.aot;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -63,6 +64,7 @@ class BeanDefinitionPropertyValueCodeGenerator {
private final List<Delegate> delegates = List.of(
new PrimitiveDelegate(),
new StringDelegate(),
new CharsetDelegate(),
new EnumDelegate(),
new ClassDelegate(),
new ResolvableTypeDelegate(),
@@ -207,6 +209,23 @@ class BeanDefinitionPropertyValueCodeGenerator {
}
/**
* {@link Delegate} for {@link Charset} types.
*/
private static class CharsetDelegate implements Delegate {
@Override
@Nullable
public CodeBlock generateCode(Object value, ResolvableType type) {
if (value instanceof Charset charset) {
return CodeBlock.of("$T.forName($S)", Charset.class, charset.name());
}
return null;
}
}
/**
* {@link Delegate} for {@link Enum} types.
*/