Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.41 KB | None | 0 0
  1. import com.fasterxml.jackson.annotation.*;
  2. import com.fasterxml.jackson.core.*;
  3. import com.fasterxml.jackson.databind.*;
  4. import com.fasterxml.jackson.databind.deser.*;
  5. import com.fasterxml.jackson.databind.deser.impl.*;
  6. import com.fasterxml.jackson.databind.deser.std.*;
  7.  
  8. import org.junit.*;
  9.  
  10. import java.io.*;
  11.  
  12. import static org.junit.Assert.*;
  13.  
  14.  
  15. public class Github1432 {
  16.  
  17. @Test
  18. public void allPropertiesHaveHasParameterReturnTrue() throws IOException {
  19. ObjectMapper objectMapper = new ObjectMapper();
  20. objectMapper.registerModule(new TestModule());
  21.  
  22.  
  23. String json = "{ " +
  24. "\"p1\": \"NotNull\"," +
  25. "\"p2\": \"NotNull\"," +
  26. "\"p3\": \"NotNull\"," +
  27. "\"p4\": \"NotNull\"," +
  28. "\"p5\": \"NotNull\"," +
  29. "\"p6\": \"NotNull\"," +
  30. "\"p7\": \"NotNull\"," +
  31. "\"p8\": \"NotNull\"," +
  32. "\"p9\": \"NotNull\"," +
  33. "\"p10\": \"NotNull\"," +
  34. "\"p11\": \"NotNull\"," +
  35. "\"p12\": \"NotNull\"," +
  36. "\"p13\": \"NotNull\"," +
  37. "\"p14\": \"NotNull\"," +
  38. "\"p15\": \"NotNull\"," +
  39. "\"p16\": \"NotNull\"," +
  40. "\"p17\": \"NotNull\"," +
  41. "\"p18\": \"NotNull\"," +
  42. "\"p19\": \"NotNull\"," +
  43. "\"p20\": \"NotNull\"," +
  44. "\"p21\": \"NotNull\"," +
  45. "\"p22\": \"NotNull\"," +
  46. "\"p23\": \"NotNull\"," +
  47. "\"p24\": \"NotNull\"," +
  48. "\"p25\": \"NotNull\"," +
  49. "\"p26\": \"NotNull\"," +
  50. "\"p27\": \"NotNull\"," +
  51. "\"p28\": \"NotNull\"," +
  52. "\"p29\": \"NotNull\"," +
  53. "\"p30\": \"NotNull\"," +
  54. "\"p31\": \"NotNull\"," +
  55. "\"p32\": \"NotNull\" " +
  56. "}";
  57.  
  58.  
  59. ClassWith32Props classWith32Props = objectMapper.readValue(json, ClassWith32Props.class);
  60.  
  61. assertEquals("NotNull", classWith32Props.p1);
  62. assertEquals("NotNull", classWith32Props.p2);
  63. assertEquals("NotNull", classWith32Props.p3);
  64. assertEquals("NotNull", classWith32Props.p4);
  65. assertEquals("NotNull", classWith32Props.p5);
  66. assertEquals("NotNull", classWith32Props.p6);
  67. assertEquals("NotNull", classWith32Props.p7);
  68. assertEquals("NotNull", classWith32Props.p8);
  69. assertEquals("NotNull", classWith32Props.p9);
  70. assertEquals("NotNull", classWith32Props.p10);
  71. assertEquals("NotNull", classWith32Props.p11);
  72. assertEquals("NotNull", classWith32Props.p12);
  73. assertEquals("NotNull", classWith32Props.p13);
  74. assertEquals("NotNull", classWith32Props.p14);
  75. assertEquals("NotNull", classWith32Props.p15);
  76. assertEquals("NotNull", classWith32Props.p16);
  77. assertEquals("NotNull", classWith32Props.p17);
  78. assertEquals("NotNull", classWith32Props.p18);
  79. assertEquals("NotNull", classWith32Props.p19);
  80. assertEquals("NotNull", classWith32Props.p20);
  81. assertEquals("NotNull", classWith32Props.p21);
  82. assertEquals("NotNull", classWith32Props.p22);
  83. assertEquals("NotNull", classWith32Props.p23);
  84. assertEquals("NotNull", classWith32Props.p24);
  85. assertEquals("NotNull", classWith32Props.p25);
  86. assertEquals("NotNull", classWith32Props.p26);
  87. assertEquals("NotNull", classWith32Props.p27);
  88. assertEquals("NotNull", classWith32Props.p28);
  89. assertEquals("NotNull", classWith32Props.p29);
  90. assertEquals("NotNull", classWith32Props.p30);
  91. assertEquals("NotNull", classWith32Props.p31);
  92. assertEquals("NotNull", classWith32Props.p32);
  93.  
  94.  
  95. }
  96.  
  97. public static class ClassWith32Props {
  98.  
  99. @JsonCreator
  100. public ClassWith32Props(
  101. @JsonProperty("p1") String p1,
  102. @JsonProperty("p2") String p2,
  103. @JsonProperty("p3") String p3,
  104. @JsonProperty("p4") String p4,
  105. @JsonProperty("p5") String p5,
  106. @JsonProperty("p6") String p6,
  107. @JsonProperty("p7") String p7,
  108. @JsonProperty("p8") String p8,
  109. @JsonProperty("p9") String p9,
  110. @JsonProperty("p10") String p10,
  111. @JsonProperty("p11") String p11,
  112. @JsonProperty("p12") String p12,
  113. @JsonProperty("p13") String p13,
  114. @JsonProperty("p14") String p14,
  115. @JsonProperty("p15") String p15,
  116. @JsonProperty("p16") String p16,
  117. @JsonProperty("p17") String p17,
  118. @JsonProperty("p18") String p18,
  119. @JsonProperty("p19") String p19,
  120. @JsonProperty("p20") String p20,
  121. @JsonProperty("p21") String p21,
  122. @JsonProperty("p22") String p22,
  123. @JsonProperty("p23") String p23,
  124. @JsonProperty("p24") String p24,
  125. @JsonProperty("p25") String p25,
  126. @JsonProperty("p26") String p26,
  127. @JsonProperty("p27") String p27,
  128. @JsonProperty("p28") String p28,
  129. @JsonProperty("p29") String p29,
  130. @JsonProperty("p30") String p30,
  131. @JsonProperty("p31") String p31,
  132. @JsonProperty("p32") String p32) {
  133. this.p1 = p1;
  134. this.p2 = p2;
  135. this.p3 = p3;
  136. this.p4 = p4;
  137. this.p5 = p5;
  138. this.p6 = p6;
  139. this.p7 = p7;
  140. this.p8 = p8;
  141. this.p9 = p9;
  142. this.p10 = p10;
  143. this.p11 = p11;
  144. this.p12 = p12;
  145. this.p13 = p13;
  146. this.p14 = p14;
  147. this.p15 = p15;
  148. this.p16 = p16;
  149. this.p17 = p17;
  150. this.p18 = p18;
  151. this.p19 = p19;
  152. this.p20 = p20;
  153. this.p21 = p21;
  154. this.p22 = p22;
  155. this.p23 = p23;
  156. this.p24 = p24;
  157. this.p25 = p25;
  158. this.p26 = p26;
  159. this.p27 = p27;
  160. this.p28 = p28;
  161. this.p29 = p29;
  162. this.p30 = p30;
  163. this.p31 = p31;
  164. this.p32 = p32;
  165. }
  166.  
  167. public final String p1;
  168. public final String p2;
  169. public final String p3;
  170. public final String p4;
  171. public final String p5;
  172. public final String p6;
  173. public final String p7;
  174. public final String p8;
  175. public final String p9;
  176. public final String p10;
  177. public final String p11;
  178. public final String p12;
  179. public final String p13;
  180. public final String p14;
  181. public final String p15;
  182. public final String p16;
  183. public final String p17;
  184. public final String p18;
  185. public final String p19;
  186. public final String p20;
  187. public final String p21;
  188. public final String p22;
  189. public final String p23;
  190. public final String p24;
  191. public final String p25;
  192. public final String p26;
  193. public final String p27;
  194. public final String p28;
  195. public final String p29;
  196. public final String p30;
  197. public final String p31;
  198. public final String p32;
  199. }
  200.  
  201.  
  202. public static class TestModule extends Module {
  203. @Override
  204. public String getModuleName() {
  205. return "test";
  206. }
  207.  
  208. @Override
  209. public Version version() {
  210. return new Version(0, 0, 0, "Test", null, null);
  211. }
  212.  
  213. @Override
  214. public void setupModule(SetupContext context) {
  215. context.addValueInstantiators((config, beanDesc, defaultInstantiator) -> new TestValueInstantiator((StdValueInstantiator) defaultInstantiator));
  216. }
  217. }
  218.  
  219.  
  220. public static class TestValueInstantiator extends StdValueInstantiator {
  221.  
  222. protected TestValueInstantiator(StdValueInstantiator src) {
  223. super(src);
  224. }
  225.  
  226. @Override
  227. public Object createFromObjectWith(DeserializationContext ctxt, SettableBeanProperty[] props, PropertyValueBuffer buffer) throws IOException {
  228. for (SettableBeanProperty prop : props) {
  229. assertTrue("prop " + prop.getName() + " was expected to have buffer.hasParameter(prop) be true but was false", buffer.hasParameter(prop));
  230. }
  231.  
  232. return super.createFromObjectWith(ctxt, props, buffer);
  233. }
  234. }
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement