|
16 | 16 |
|
17 | 17 | package org.springframework.aot.hint;
|
18 | 18 |
|
| 19 | +import java.io.IOException; |
19 | 20 | import java.lang.reflect.Type;
|
| 21 | +import java.time.LocalDate; |
20 | 22 | import java.util.List;
|
21 | 23 | import java.util.Set;
|
22 | 24 |
|
23 | 25 | import com.fasterxml.jackson.annotation.JsonProperty;
|
| 26 | +import com.fasterxml.jackson.core.JacksonException; |
| 27 | +import com.fasterxml.jackson.core.JsonParser; |
| 28 | +import com.fasterxml.jackson.databind.DeserializationContext; |
24 | 29 | import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
25 | 30 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
26 | 31 | import com.fasterxml.jackson.databind.annotation.JsonNaming;
|
27 | 32 | import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
|
| 33 | +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; |
28 | 34 | import org.junit.jupiter.api.Test;
|
29 | 35 |
|
30 | 36 | import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
@@ -265,6 +271,15 @@ void registerTypeForJacksonCustomStrategy() {
|
265 | 271 | .accepts(this.hints);
|
266 | 272 | }
|
267 | 273 |
|
| 274 | + @Test |
| 275 | + void registerTypeForAnnotationOnMethodAndField() { |
| 276 | + bindingRegistrar.registerReflectionHints(this.hints.reflection(), SampleClassWithJsonProperty.class); |
| 277 | + assertThat(RuntimeHintsPredicates.reflection().onType(CustomDeserializer1.class).withMemberCategory(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)) |
| 278 | + .accepts(this.hints); |
| 279 | + assertThat(RuntimeHintsPredicates.reflection().onType(CustomDeserializer2.class).withMemberCategory(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)) |
| 280 | + .accepts(this.hints); |
| 281 | + } |
| 282 | + |
268 | 283 |
|
269 | 284 | static class SampleEmptyClass {
|
270 | 285 | }
|
@@ -359,9 +374,11 @@ public String getNameProperty() {
|
359 | 374 | static class SampleClassWithJsonProperty {
|
360 | 375 |
|
361 | 376 | @JsonProperty
|
| 377 | + @JsonDeserialize(using = CustomDeserializer1.class) |
362 | 378 | private String privateField = "";
|
363 | 379 |
|
364 | 380 | @JsonProperty
|
| 381 | + @JsonDeserialize(using = CustomDeserializer2.class) |
365 | 382 | String packagePrivateMethod() {
|
366 | 383 | return "";
|
367 | 384 | }
|
@@ -393,4 +410,28 @@ public SampleRecordWithJacksonCustomStrategy build() {
|
393 | 410 |
|
394 | 411 | }
|
395 | 412 |
|
| 413 | + static class CustomDeserializer1 extends StdDeserializer<LocalDate> { |
| 414 | + |
| 415 | + public CustomDeserializer1() { |
| 416 | + super(CustomDeserializer1.class); |
| 417 | + } |
| 418 | + |
| 419 | + @Override |
| 420 | + public LocalDate deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { |
| 421 | + return null; |
| 422 | + } |
| 423 | + } |
| 424 | + |
| 425 | + static class CustomDeserializer2 extends StdDeserializer<LocalDate> { |
| 426 | + |
| 427 | + public CustomDeserializer2() { |
| 428 | + super(CustomDeserializer2.class); |
| 429 | + } |
| 430 | + |
| 431 | + @Override |
| 432 | + public LocalDate deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { |
| 433 | + return null; |
| 434 | + } |
| 435 | + } |
| 436 | + |
396 | 437 | }
|
0 commit comments