|
| 1 | +package tools.jackson.databind.tofix; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Test; |
| 4 | + |
| 5 | +import tools.jackson.databind.*; |
| 6 | +import tools.jackson.databind.testutil.DatabindTestUtil; |
| 7 | +import tools.jackson.databind.testutil.failure.JacksonTestFailureExpected; |
| 8 | + |
| 9 | +import static org.junit.jupiter.api.Assertions.*; |
| 10 | + |
| 11 | +// [databind#5152] Support "iPhone" style capitalized properties |
| 12 | +public class IPhoneStyleProperty5152Test |
| 13 | + extends DatabindTestUtil |
| 14 | +{ |
| 15 | + static class IPhoneBean { |
| 16 | + private String iPhone; |
| 17 | + |
| 18 | + public String getIPhone() { |
| 19 | + return iPhone; |
| 20 | + } |
| 21 | + |
| 22 | + public void setIPhone(String value) { |
| 23 | + iPhone = value; |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + static class RegularBean { |
| 28 | + private String phoneNumber; |
| 29 | + |
| 30 | + public String getPhoneNumber() { |
| 31 | + return phoneNumber; |
| 32 | + } |
| 33 | + |
| 34 | + public void setPhoneNumber(String value) { |
| 35 | + phoneNumber = value; |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + // [databind#2835]: "dLogHeader" property |
| 40 | + static class DLogHeaderBean { |
| 41 | + private String DLogHeader; |
| 42 | + |
| 43 | + public String getDLogHeader() { |
| 44 | + return DLogHeader; |
| 45 | + } |
| 46 | + |
| 47 | + public void setDLogHeader(String value) { |
| 48 | + DLogHeader = value; |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + static class KBSBroadCastingBean { |
| 53 | + private String KBSBroadCasting; |
| 54 | + |
| 55 | + public String getKBSBroadCasting() { |
| 56 | + return KBSBroadCasting; |
| 57 | + } |
| 58 | + |
| 59 | + public void setKBSBroadCasting(String value) { |
| 60 | + KBSBroadCasting = value; |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + static class PhoneBean { |
| 65 | + private String Phone; |
| 66 | + |
| 67 | + public String getPhone() { |
| 68 | + return Phone; |
| 69 | + } |
| 70 | + public void setPhone(String value) { |
| 71 | + Phone = value; |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + private final ObjectMapper MAPPER = jsonMapperBuilder() |
| 76 | + .build(); |
| 77 | + |
| 78 | + @JacksonTestFailureExpected |
| 79 | + @Test |
| 80 | + public void testIPhoneStyleProperty() throws Exception { |
| 81 | + // Test with iPhone style property |
| 82 | + String json = "{\"iPhone\":\"iPhone 15\"}"; |
| 83 | + IPhoneBean result = MAPPER.readValue(json, IPhoneBean.class); |
| 84 | + assertNotNull(result); |
| 85 | + assertEquals("iPhone 15", result.getIPhone()); |
| 86 | + |
| 87 | + // Test serialization |
| 88 | + String serialized = MAPPER.writeValueAsString(result); |
| 89 | + assertEquals("{\"iPhone\":\"iPhone 15\"}", serialized); |
| 90 | + } |
| 91 | + |
| 92 | + @Test |
| 93 | + public void testRegularPojoProperty() throws Exception { |
| 94 | + // Test with regular POJO property |
| 95 | + String json = "{\"phoneNumber\":\"123-456-7890\"}"; |
| 96 | + RegularBean result = MAPPER.readValue(json, RegularBean.class); |
| 97 | + assertNotNull(result); |
| 98 | + assertEquals("123-456-7890", result.getPhoneNumber()); |
| 99 | + |
| 100 | + // Test serialization |
| 101 | + String serialized = MAPPER.writeValueAsString(result); |
| 102 | + assertEquals("{\"phoneNumber\":\"123-456-7890\"}", serialized); |
| 103 | + } |
| 104 | + |
| 105 | + // [databind#2835]: "dLogHeader" property |
| 106 | + @JacksonTestFailureExpected |
| 107 | + @Test |
| 108 | + public void testDLogHeaderStyleProperty() throws Exception { |
| 109 | + // Test with DLogHeader style property |
| 110 | + String json = "{\"dLogHeader\":\"Debug Log Header\"}"; |
| 111 | + DLogHeaderBean result = MAPPER.readValue(json, DLogHeaderBean.class); |
| 112 | + assertNotNull(result); |
| 113 | + assertEquals("Debug Log Header", result.getDLogHeader()); |
| 114 | + |
| 115 | + // Test serialization |
| 116 | + String serialized = MAPPER.writeValueAsString(result); |
| 117 | + assertEquals("{\"dLogHeader\":\"Debug Log Header\"}", serialized); |
| 118 | + } |
| 119 | + |
| 120 | + // 20-May-2025, tatu: Somehow passes on 3.0, fails on 2.19 |
| 121 | + //@JacksonTestFailureExpected |
| 122 | + @Test |
| 123 | + public void testKBSBroadCastingStyleProperty() throws Exception { |
| 124 | + // Test with KBSBroadCasting style property |
| 125 | + String json = "{\"KBSBroadCasting\":\"Korean Broadcasting System\"}"; |
| 126 | + KBSBroadCastingBean result = MAPPER.readValue(json, KBSBroadCastingBean.class); |
| 127 | + assertNotNull(result); |
| 128 | + assertEquals("Korean Broadcasting System", result.getKBSBroadCasting()); |
| 129 | + |
| 130 | + // Test serialization |
| 131 | + String serialized = MAPPER.writeValueAsString(result); |
| 132 | + assertEquals("{\"KBSBroadCasting\":\"Korean Broadcasting System\"}", serialized); |
| 133 | + } |
| 134 | + |
| 135 | + @JacksonTestFailureExpected |
| 136 | + @Test |
| 137 | + public void testPhoneStyleProperty() throws Exception { |
| 138 | + // Test with Phone style property |
| 139 | + String json = "{\"Phone\":\"iPhone 15\"}"; |
| 140 | + PhoneBean result = MAPPER.readValue(json, PhoneBean.class); |
| 141 | + assertNotNull(result); |
| 142 | + assertEquals("iPhone 15", result.getPhone()); |
| 143 | + |
| 144 | + // Test serialization |
| 145 | + String serialized = MAPPER.writeValueAsString(result); |
| 146 | + assertEquals("{\"Phone\":\"iPhone 15\"}", serialized); |
| 147 | + } |
| 148 | +} |
0 commit comments