2020 * =========================LICENSE_END==================================
2121 */
2222
23- import static org .assertj .core .api .FactoryBasedNavigableListAssert .assertThat ;
23+ import static org .assertj .core .api .Assertions .assertThat ;
24+ import static org .xrpl .xrpl4j .model .AddressConstants .ACCOUNT_ZERO ;
2425
2526import com .fasterxml .jackson .core .JsonProcessingException ;
2627import com .google .common .primitives .UnsignedInteger ;
28+ import com .google .common .primitives .UnsignedLong ;
2729import org .assertj .core .api .Assertions ;
2830import org .json .JSONException ;
2931import org .junit .jupiter .api .Test ;
3638import org .xrpl .xrpl4j .model .transactions .UnlModify ;
3739import org .xrpl .xrpl4j .model .transactions .XrpCurrencyAmount ;
3840
41+ import java .util .Collections ;
42+ import java .util .Map ;
43+
3944public class UnlModifyJsonTests extends AbstractJsonTest {
4045
4146 @ Test
@@ -64,12 +69,12 @@ public void testJsonWithAccountZero() throws JsonProcessingException, JSONExcept
6469 @ Test
6570 public void testJsonWithAccountZeroAndUnknownFields () throws JsonProcessingException , JSONException {
6671 UnlModify unlModify = UnlModify .builder ()
72+ .putUnknownFields ("Foo" , "Bar" )
6773 .fee (XrpCurrencyAmount .ofDrops (12 ))
6874 .sequence (UnsignedInteger .valueOf (2470665 ))
6975 .ledgerSequence (LedgerIndex .of (UnsignedInteger .valueOf (67850752 )))
7076 .unlModifyValidator ("EDB6FC8E803EE8EDC2793F1EC917B2EE41D35255618DEB91D3F9B1FC89B75D4539" )
7177 .unlModifyDisabling (UnsignedInteger .valueOf (1 ))
72- .putUnknownFields ("Foo" , "Bar" )
7378 .build ();
7479
7580 String json = "{" +
@@ -96,42 +101,79 @@ public void testJsonWithEmptyAccount() throws JsonProcessingException, JSONExcep
96101 .unlModifyDisabling (UnsignedInteger .valueOf (1 ))
97102 .build ();
98103
99- String json = "{" +
100- "\" Account\" :\" \" ," +
104+ // What we expect the ObjectMapper to Serialize (given the above object)
105+ String expectedSerializedJson = "{" +
106+ "\" Account\" :\" " + ACCOUNT_ZERO + "\" ," +
101107 "\" Fee\" :\" 12\" ," +
102108 "\" LedgerSequence\" :67850752," +
103109 "\" Sequence\" :2470665," +
104110 "\" SigningPubKey\" :\" \" ," +
105111 "\" TransactionType\" :\" UNLModify\" ," +
106112 "\" UNLModifyDisabling\" :1," +
107- "\" UNLModifyValidator\" :\" EDB6FC8E803EE8EDC2793F1EC917B2EE41D35255618DEB91D3F9B1FC89B75D4539\" }" ;
113+ "\" UNLModifyValidator\" :\" EDB6FC8E803EE8EDC2793F1EC917B2EE41D35255618DEB91D3F9B1FC89B75D4539\" " +
114+ "}" ;
108115
109- assertCanSerializeAndDeserialize (unlModify , json );
116+ String serialized = objectMapper .writeValueAsString (unlModify );
117+ JSONAssert .assertEquals (expectedSerializedJson , serialized , JSONCompareMode .STRICT );
118+
119+ // What we provide the ObjectMapper to Deserialize
120+ String expectedDeserializedJson = "{" +
121+ "\" Account\" :\" \" ," + // <-- The crux of the test!
122+ "\" Fee\" :\" 12\" ," +
123+ "\" LedgerSequence\" :67850752," +
124+ "\" Sequence\" :2470665," +
125+ "\" SigningPubKey\" :\" \" ," +
126+ "\" TransactionType\" :\" UNLModify\" ," +
127+ "\" UNLModifyDisabling\" :1," +
128+ "\" UNLModifyValidator\" :\" EDB6FC8E803EE8EDC2793F1EC917B2EE41D35255618DEB91D3F9B1FC89B75D4539\" " +
129+ "}" ;
130+
131+ Transaction deserialized = objectMapper .readValue (expectedDeserializedJson , Transaction .class );
132+ assertThat (deserialized ).isEqualTo (unlModify );
110133 }
111134
112135 @ Test
113136 public void testJsonWithEmptyAccountAndUnknownFields () throws JsonProcessingException , JSONException {
114137 UnlModify unlModify = UnlModify .builder ()
138+ .putUnknownFields ("Foo" , "Bar" )
115139 .fee (XrpCurrencyAmount .ofDrops (12 ))
116140 .sequence (UnsignedInteger .valueOf (2470665 ))
117141 .ledgerSequence (LedgerIndex .of (UnsignedInteger .valueOf (67850752 )))
118142 .unlModifyValidator ("EDB6FC8E803EE8EDC2793F1EC917B2EE41D35255618DEB91D3F9B1FC89B75D4539" )
119143 .unlModifyDisabling (UnsignedInteger .valueOf (1 ))
120- .putUnknownFields ("Foo" , "Bar" )
121144 .build ();
122145
123- String json = "{" +
124- "\" Foo\" : \" Bar\" ,\n " +
125- "\" Account\" :\" \" ," +
146+ // What we expect the ObjectMapper to Serialize (given the above object)
147+ String expectedSerializedJson = "{" +
148+ "\" Account\" :\" " + ACCOUNT_ZERO + "\" ," +
149+ "\" Foo\" : \" Bar\" ,\n " + // <-- The crux of the test!
126150 "\" Fee\" :\" 12\" ," +
127151 "\" LedgerSequence\" :67850752," +
128152 "\" Sequence\" :2470665," +
129153 "\" SigningPubKey\" :\" \" ," +
130154 "\" TransactionType\" :\" UNLModify\" ," +
131155 "\" UNLModifyDisabling\" :1," +
132- "\" UNLModifyValidator\" :\" EDB6FC8E803EE8EDC2793F1EC917B2EE41D35255618DEB91D3F9B1FC89B75D4539\" }" ;
156+ "\" UNLModifyValidator\" :\" EDB6FC8E803EE8EDC2793F1EC917B2EE41D35255618DEB91D3F9B1FC89B75D4539\" " +
157+ "}" ;
133158
134- assertCanSerializeAndDeserialize (unlModify , json );
159+ String serialized = objectMapper .writeValueAsString (unlModify );
160+ JSONAssert .assertEquals (expectedSerializedJson , serialized , JSONCompareMode .STRICT );
161+
162+ // What we provide the ObjectMapper to Deserialize
163+ String expectedDeserializedJson = "{" +
164+ "\" Foo\" : \" Bar\" ,\n " + // <-- The crux of the test!
165+ "\" Account\" :\" \" ," + // <-- The crux of the test!
166+ "\" Fee\" :\" 12\" ," +
167+ "\" LedgerSequence\" :67850752," +
168+ "\" Sequence\" :2470665," +
169+ "\" SigningPubKey\" :\" \" ," +
170+ "\" TransactionType\" :\" UNLModify\" ," +
171+ "\" UNLModifyDisabling\" :1," +
172+ "\" UNLModifyValidator\" :\" EDB6FC8E803EE8EDC2793F1EC917B2EE41D35255618DEB91D3F9B1FC89B75D4539\" " +
173+ "}" ;
174+
175+ Transaction deserialized = objectMapper .readValue (expectedDeserializedJson , Transaction .class );
176+ assertThat (deserialized ).isEqualTo (unlModify );
135177 }
136178
137179 @ Test
@@ -144,7 +186,8 @@ public void testJsonWithMissingAccount() throws JsonProcessingException, JSONExc
144186 .unlModifyDisabling (UnsignedInteger .valueOf (1 ))
145187 .build ();
146188
147- String json = "{" +
189+ String expectedJson = "{" +
190+ "\" Account\" :\" " + ACCOUNT_ZERO + "\" ," +
148191 "\" Fee\" :\" 12\" ," +
149192 "\" LedgerSequence\" :67850752," +
150193 "\" Sequence\" :2470665," +
@@ -153,7 +196,20 @@ public void testJsonWithMissingAccount() throws JsonProcessingException, JSONExc
153196 "\" UNLModifyDisabling\" :1," +
154197 "\" UNLModifyValidator\" :\" EDB6FC8E803EE8EDC2793F1EC917B2EE41D35255618DEB91D3F9B1FC89B75D4539\" }" ;
155198
156- assertCanSerializeAndDeserialize (unlModify , json );
199+ String serialized = objectMapper .writeValueAsString (unlModify );
200+ JSONAssert .assertEquals (expectedJson , serialized , JSONCompareMode .STRICT );
201+
202+ String jsonForDeserialization = "{" +
203+ "\" Fee\" :\" 12\" ," +
204+ "\" LedgerSequence\" :67850752," +
205+ "\" Sequence\" :2470665," +
206+ "\" SigningPubKey\" :\" \" ," +
207+ "\" TransactionType\" :\" UNLModify\" ," +
208+ "\" UNLModifyDisabling\" :1," +
209+ "\" UNLModifyValidator\" :\" EDB6FC8E803EE8EDC2793F1EC917B2EE41D35255618DEB91D3F9B1FC89B75D4539\" }" ;
210+
211+ Transaction deserialized = objectMapper .readValue (jsonForDeserialization , Transaction .class );
212+ assertThat (deserialized ).isEqualTo (unlModify );
157213 }
158214
159215 @ Test
@@ -164,28 +220,43 @@ public void testJsonWithMissingAccountAndUnknownFields() throws JsonProcessingEx
164220 .ledgerSequence (LedgerIndex .of (UnsignedInteger .valueOf (67850752 )))
165221 .unlModifyValidator ("EDB6FC8E803EE8EDC2793F1EC917B2EE41D35255618DEB91D3F9B1FC89B75D4539" )
166222 .unlModifyDisabling (UnsignedInteger .valueOf (1 ))
167- .putUnknownFields ("Foo" , "Bar" )
168223 .build ();
169224
170- String json = "{" +
171- "\" Foo\" : \" Bar\" ,\n " +
225+ // What we expect the ObjectMapper to Serialize (given the above object)
226+ String expectedSerializedJson = "{" +
227+ "\" Account\" :\" " + ACCOUNT_ZERO + "\" ," +
172228 "\" Fee\" :\" 12\" ," +
173229 "\" LedgerSequence\" :67850752," +
174230 "\" Sequence\" :2470665," +
175231 "\" SigningPubKey\" :\" \" ," +
176232 "\" TransactionType\" :\" UNLModify\" ," +
177233 "\" UNLModifyDisabling\" :1," +
178- "\" UNLModifyValidator\" :\" EDB6FC8E803EE8EDC2793F1EC917B2EE41D35255618DEB91D3F9B1FC89B75D4539\" }" ;
234+ "\" UNLModifyValidator\" :\" EDB6FC8E803EE8EDC2793F1EC917B2EE41D35255618DEB91D3F9B1FC89B75D4539\" " +
235+ "}" ;
179236
180- assertCanSerializeAndDeserialize (unlModify , json );
237+ String serialized = objectMapper .writeValueAsString (unlModify );
238+ JSONAssert .assertEquals (expectedSerializedJson , serialized , JSONCompareMode .STRICT );
239+
240+ // What we provide the ObjectMapper to Deserialize
241+ String expectedDeserializedJson = "{" +
242+ "\" Account\" :\" " + ACCOUNT_ZERO + "\" ," +
243+ "\" Fee\" :\" 12\" ," +
244+ "\" LedgerSequence\" :67850752," +
245+ "\" Sequence\" :2470665," +
246+ "\" SigningPubKey\" :\" \" ," +
247+ "\" TransactionType\" :\" UNLModify\" ," +
248+ "\" UNLModifyDisabling\" :1," +
249+ "\" UNLModifyValidator\" :\" EDB6FC8E803EE8EDC2793F1EC917B2EE41D35255618DEB91D3F9B1FC89B75D4539\" " +
250+ "}" ;
251+
252+ Transaction deserialized = objectMapper .readValue (expectedDeserializedJson , Transaction .class );
253+ assertThat (deserialized ).isEqualTo (unlModify );
181254 }
182255
183256 // Using Transcation
184257 // Using Immutable
185258 // Using UnlModify
186259
187-
188-
189260// @Test
190261// public void testDeserializeJson() throws JsonProcessingException {
191262// String json = "{" +
0 commit comments