|
| 1 | +package com.fasterxml.jackson.databind.deser.creators; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Test; |
| 4 | + |
| 5 | +import com.fasterxml.jackson.annotation.JsonCreator; |
| 6 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 7 | +import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; |
| 8 | + |
| 9 | +import static org.junit.jupiter.api.Assertions.assertSame; |
| 10 | + |
| 11 | +// [databind#4688] |
| 12 | +public class SingletonDelegatingCreatorTest extends DatabindTestUtil |
| 13 | +{ |
| 14 | + static final class NoFieldSingletonWithDelegatingCreator { |
| 15 | + static final NoFieldSingletonWithDelegatingCreator INSTANCE = new NoFieldSingletonWithDelegatingCreator(); |
| 16 | + |
| 17 | + private NoFieldSingletonWithDelegatingCreator() {} |
| 18 | + |
| 19 | + @JsonCreator(mode = JsonCreator.Mode.DELEGATING) |
| 20 | + static NoFieldSingletonWithDelegatingCreator of() { |
| 21 | + return INSTANCE; |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + static final class NoFieldSingletonWithPropertiesCreator { |
| 26 | + static final NoFieldSingletonWithPropertiesCreator INSTANCE = new NoFieldSingletonWithPropertiesCreator(); |
| 27 | + |
| 28 | + private NoFieldSingletonWithPropertiesCreator() {} |
| 29 | + |
| 30 | + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) |
| 31 | + static NoFieldSingletonWithPropertiesCreator of() { |
| 32 | + return INSTANCE; |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + static final class NoFieldSingletonWithDefaultCreator { |
| 37 | + static final NoFieldSingletonWithDefaultCreator INSTANCE = new NoFieldSingletonWithDefaultCreator(); |
| 38 | + |
| 39 | + private NoFieldSingletonWithDefaultCreator() {} |
| 40 | + |
| 41 | + @JsonCreator |
| 42 | + static NoFieldSingletonWithDefaultCreator of() { |
| 43 | + return INSTANCE; |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + /* |
| 48 | + /********************************************************************** |
| 49 | + /* Test methods |
| 50 | + /********************************************************************** |
| 51 | + */ |
| 52 | + |
| 53 | + private final ObjectMapper MAPPER = newJsonMapper(); |
| 54 | + |
| 55 | + @Test |
| 56 | + public void testNoFieldSingletonWithDelegatingCreator() throws Exception |
| 57 | + { |
| 58 | + NoFieldSingletonWithDelegatingCreator deserialized = MAPPER.readValue("{}", |
| 59 | + NoFieldSingletonWithDelegatingCreator.class); |
| 60 | + assertSame(NoFieldSingletonWithDelegatingCreator.INSTANCE, deserialized); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + public void testNoFieldSingletonWithPropertiesCreator() throws Exception |
| 65 | + { |
| 66 | + NoFieldSingletonWithPropertiesCreator deserialized = MAPPER.readValue("{}", |
| 67 | + NoFieldSingletonWithPropertiesCreator.class); |
| 68 | + assertSame(NoFieldSingletonWithPropertiesCreator.INSTANCE, deserialized); |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + public void testNoFieldSingletonWithDefaultCreator() throws Exception |
| 73 | + { |
| 74 | + NoFieldSingletonWithDefaultCreator deserialized = MAPPER.readValue("{}", |
| 75 | + NoFieldSingletonWithDefaultCreator.class); |
| 76 | + assertSame(NoFieldSingletonWithDefaultCreator.INSTANCE, deserialized); |
| 77 | + } |
| 78 | +} |
0 commit comments