Skip to content

Commit a1f4cdf

Browse files
committed
Add missing reflection hint on MonetaryAmount
Fixes gh-31266
1 parent 8074f93 commit a1f4cdf

File tree

4 files changed

+92
-3
lines changed

4 files changed

+92
-3
lines changed

spring-context/src/main/java/org/springframework/format/support/DefaultFormattingConversionService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,8 +37,8 @@
3737
* as {@code DefaultConversionService} exposes its own
3838
* {@link DefaultConversionService#addDefaultConverters addDefaultConverters} method.
3939
*
40-
* <p>Automatically registers formatters for JSR-354 Money &amp; Currency, JSR-310 Date-Time
41-
* and/or Joda-Time 2.x, depending on the presence of the corresponding API on the classpath.
40+
* <p>Automatically registers formatters for JSR-354 Money &amp; Currency and JSR-310 Date-Time
41+
* depending on the presence of the corresponding API on the classpath.
4242
*
4343
* @author Chris Beams
4444
* @author Juergen Hoeller
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2002-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.format.support;
18+
19+
import org.springframework.aot.hint.RuntimeHints;
20+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
21+
import org.springframework.aot.hint.TypeReference;
22+
23+
/**
24+
* {@link RuntimeHintsRegistrar} to register hints for {@link DefaultFormattingConversionService}.
25+
*
26+
* @author Brian Clozel
27+
* @since 6.1
28+
*/
29+
class FormattingConversionServiceRuntimeHints implements RuntimeHintsRegistrar {
30+
31+
@Override
32+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
33+
hints.reflection().registerType(TypeReference.of("javax.money.MonetaryAmount"));
34+
}
35+
}

spring-context/src/main/resources/META-INF/spring/aot.factories

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
org.springframework.aot.hint.RuntimeHintsRegistrar= \
2+
org.springframework.format.support.FormattingConversionServiceRuntimeHints
3+
14
org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor= \
25
org.springframework.context.aot.ReflectiveProcessorBeanFactoryInitializationAotProcessor
36

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2002-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.format.support;
18+
19+
import org.junit.jupiter.api.BeforeEach;
20+
import org.junit.jupiter.api.Test;
21+
22+
import org.springframework.aot.hint.RuntimeHints;
23+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
24+
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
25+
import org.springframework.core.io.support.SpringFactoriesLoader;
26+
import org.springframework.util.ClassUtils;
27+
28+
import static org.assertj.core.api.Assertions.assertThat;
29+
30+
/**
31+
* Tests for {@link FormattingConversionServiceRuntimeHints}.
32+
* @author Brian Clozel
33+
*/
34+
class FormattingConversionServiceRuntimeHintsTests {
35+
36+
private RuntimeHints hints;
37+
38+
@BeforeEach
39+
void setup() {
40+
this.hints = new RuntimeHints();
41+
SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories")
42+
.load(RuntimeHintsRegistrar.class).forEach(registrar -> registrar
43+
.registerHints(this.hints, ClassUtils.getDefaultClassLoader()));
44+
}
45+
46+
@Test
47+
void montearyAmountHasHints() {
48+
assertThat(RuntimeHintsPredicates.reflection().onType(javax.money.MonetaryAmount.class)).accepts(this.hints);
49+
}
50+
51+
}

0 commit comments

Comments
 (0)