|
5 | 5 | import com.google.gson.Gson;
|
6 | 6 | import com.google.gson.GsonBuilder;
|
7 | 7 | import org.json.JSONException;
|
| 8 | +import org.junit.Ignore; |
8 | 9 | import org.junit.Test;
|
9 | 10 | import org.skyscreamer.jsonassert.JSONAssert;
|
10 | 11 |
|
| 12 | +import java.math.BigDecimal; |
11 | 13 | import java.time.LocalDate;
|
12 | 14 | import java.time.LocalDateTime;
|
13 |
| -import java.util.Objects; |
| 15 | +import java.util.*; |
14 | 16 |
|
15 | 17 | import static org.junit.Assert.assertEquals;
|
16 | 18 |
|
@@ -157,26 +159,128 @@ private static class TestResponse {
|
157 | 159 | @B2Json.optional(omitNull = true)
|
158 | 160 | public final LocalDate localDate;
|
159 | 161 |
|
| 162 | + @B2Json.required |
| 163 | + public final Map<Integer, Map<String, BigDecimal>> revenueMap; |
| 164 | + |
| 165 | + @B2Json.required |
| 166 | + public final Map<String, Long> simpleMap; |
| 167 | + |
| 168 | + @B2Json.required |
| 169 | + public final Set<String> categories; |
| 170 | + |
160 | 171 | @B2Json.constructor(params = "" +
|
161 | 172 | "str," +
|
162 | 173 | "message," +
|
163 | 174 | "reason," +
|
164 | 175 | "succeeded," +
|
165 | 176 | "status," +
|
166 | 177 | "localDateTime," +
|
167 |
| - "localDate" |
| 178 | + "localDate," + |
| 179 | + "revenueMap," + |
| 180 | + "simpleMap," + |
| 181 | + "categories" |
168 | 182 | )
|
169 |
| - public TestResponse(String str, String message, String reason, boolean succeeded, int status, LocalDateTime localDateTime, LocalDate localDate) { |
| 183 | + public TestResponse(String str, String message, String reason, boolean succeeded, int status, LocalDateTime localDateTime, LocalDate localDate, |
| 184 | + Map<Integer, Map<String, BigDecimal>> revenueMap, |
| 185 | + Map<String, Long> simpleMap, |
| 186 | + Set<String> categories) { |
170 | 187 | this.str = str;
|
171 | 188 | this.message = message;
|
172 | 189 | this.reason = reason;
|
173 | 190 | this.succeeded = succeeded;
|
174 | 191 | this.status = status;
|
175 | 192 | this.localDateTime = localDateTime;
|
176 | 193 | this.localDate = localDate;
|
| 194 | + this.simpleMap = simpleMap; |
| 195 | + this.revenueMap = revenueMap; |
| 196 | + this.categories = categories; |
177 | 197 | }
|
178 | 198 | }
|
179 | 199 |
|
| 200 | +// @Test |
| 201 | +// public void testResponseUsingB2Json() throws B2JsonException, JSONException { |
| 202 | +// Map<String, Map<String, BigDecimal>> revenueMap = new TreeMap<>(); |
| 203 | +// Map<String, Long> simpleMap = new TreeMap<>(); |
| 204 | +// TestResponse obj = new TestResponse("str", |
| 205 | +// "message", |
| 206 | +// "reason", |
| 207 | +// true, |
| 208 | +// 200, |
| 209 | +// LocalDateTime.of(2023, 03, 31, 12, 21), |
| 210 | +// LocalDate.of(2023, 03, 31), |
| 211 | +// revenueMap, |
| 212 | +// simpleMap, |
| 213 | +// Set.of("test")); |
| 214 | +// System.out.println("obj is: " + obj); |
| 215 | +// String expected = "{\n" + |
| 216 | +// " \"categories\": [\n" + |
| 217 | +// " \"test\"\n" + |
| 218 | +// " ],\n" + |
| 219 | +// " \"localDate\": \"20230331\",\n" + |
| 220 | +// " \"localDateTime\": \"d20230331_m122100\",\n" + |
| 221 | +// " \"message\": \"message\",\n" + |
| 222 | +// " \"reason\": \"reason\",\n" + |
| 223 | +// " \"revenueMap\": {},\n" + |
| 224 | +// " \"simpleMap\": {},\n" + |
| 225 | +// " \"status\": 200,\n" + |
| 226 | +// " \"str\": \"str\",\n" + |
| 227 | +// " \"succeeded\": true\n" + |
| 228 | +// "}"; |
| 229 | +// System.out.println("b2Json.toJson(obj): " + b2Json.toJson(obj)); |
| 230 | +// JSONAssert.assertEquals(expected, b2Json.toJson(obj), true); |
| 231 | +// } |
| 232 | + |
| 233 | + @Test |
| 234 | + @Ignore |
| 235 | + public void testResponseUsingGson() throws JSONException { |
| 236 | + Map<Integer, Map<String, BigDecimal>> revenueMap = new TreeMap<>(); |
| 237 | + revenueMap.put(123, new HashMap<>()); |
| 238 | + Map<String, Long> simpleMap = new TreeMap<>(); |
| 239 | + TestResponse obj = new TestResponse("str", |
| 240 | + "message", |
| 241 | + "reason", |
| 242 | + true, |
| 243 | + 200, |
| 244 | + LocalDateTime.of(2023, 03, 31, 12, 21), |
| 245 | + LocalDate.of(2023, 03, 31), |
| 246 | + revenueMap, |
| 247 | + simpleMap, |
| 248 | + Set.of("test")); |
| 249 | + System.out.println("obj is: " + obj); |
| 250 | + String expected = "{\n" + |
| 251 | + " \"str\": \"str\",\n" + |
| 252 | + " \"message\": \"message\",\n" + |
| 253 | + " \"reason\": \"reason\",\n" + |
| 254 | + " \"succeeded\": true,\n" + |
| 255 | + " \"status\": 200,\n" + |
| 256 | + " \"localDateTime\": {\n" + |
| 257 | + " \"date\": {\n" + |
| 258 | + " \"year\": 2023,\n" + |
| 259 | + " \"month\": 3,\n" + |
| 260 | + " \"day\": 31\n" + |
| 261 | + " },\n" + |
| 262 | + " \"time\": {\n" + |
| 263 | + " \"hour\": 12,\n" + |
| 264 | + " \"minute\": 21,\n" + |
| 265 | + " \"second\": 0,\n" + |
| 266 | + " \"nano\": 0\n" + |
| 267 | + " }\n" + |
| 268 | + " },\n" + |
| 269 | + " \"localDate\": {\n" + |
| 270 | + " \"year\": 2023,\n" + |
| 271 | + " \"month\": 3,\n" + |
| 272 | + " \"day\": 31\n" + |
| 273 | + " },\n" + |
| 274 | + " \"revenueMap\": {},\n" + |
| 275 | + " \"simpleMap\": {},\n" + |
| 276 | + " \"categories\": [\n" + |
| 277 | + " \"test\"\n" + |
| 278 | + " ]\n" + |
| 279 | + "}"; |
| 280 | + System.out.println("b2Json.toJson(obj): " + gson.toJson(obj)); |
| 281 | + JSONAssert.assertEquals(expected, gson.toJson(obj), true); |
| 282 | + } |
| 283 | + |
180 | 284 | @Test
|
181 | 285 | public void testObject() throws B2JsonException {
|
182 | 286 | String json = "{\n" +
|
|
0 commit comments