@@ -327,20 +327,25 @@ public static <T> T toPair(BosObjectSummary bosObject, Map<String, String> index
327
327
328
328
public static <T > T toPair (JsonObject json , Map <String , String > indexMap , KeyValuePair <String , T > pair ) throws IOException {
329
329
if (json == null ) throw new IOException ("empty jsonObject." );
330
+ String field ;
330
331
JsonElement jsonElement ;
331
332
for (String index : indexMap .keySet ()) {
333
+ field = indexMap .get (index );
332
334
jsonElement = json .get (index );
333
335
// JsonUtils.toString(null) 和 JsonUtils.toString(JsonNull.INSTANCE) 均为 null
334
- if (jsonElement instanceof JsonPrimitive ) {
335
- JsonPrimitive primitive = jsonElement .getAsJsonPrimitive ();
336
- if (primitive .isBoolean ()) pair .put (indexMap .get (index ), JsonUtils .fromJson (jsonElement , Boolean .class ));
337
- else if (primitive .isNumber ()) pair .put (indexMap .get (index ), JsonUtils .fromJson (jsonElement , Long .class ));
338
- else pair .put (indexMap .get (index ), jsonElement .toString ());
339
- } else {
336
+ if (longFields .contains (field )) pair .put (field , jsonElement .getAsLong ());
337
+ else if (intFields .contains (field )) pair .put (field , jsonElement .getAsInt ());
338
+ // else if (jsonElement instanceof JsonPrimitive) {
339
+ // JsonPrimitive primitive = jsonElement.getAsJsonPrimitive();
340
+ // if (primitive.isBoolean()) pair.put(indexMap.get(index), JsonUtils.fromJson(jsonElement, Boolean.class));
341
+ // else if (primitive.isNumber()) pair.put(indexMap.get(index), JsonUtils.fromJson(jsonElement, Long.class));
342
+ // else pair.put(indexMap.get(index), jsonElement.toString());
343
+ // }
344
+ else {
340
345
try {
341
- pair .put (indexMap . get ( index ) , JsonUtils .toString (jsonElement ));
346
+ pair .put (field , JsonUtils .toString (jsonElement ));
342
347
} catch (JsonSyntaxException e ) {
343
- pair .put (indexMap . get ( index ) , String .valueOf (jsonElement ));
348
+ pair .put (field , String .valueOf (jsonElement ));
344
349
}
345
350
}
346
351
}
@@ -562,14 +567,16 @@ public static <T> T toPair(JsonObject json, List<String> fields, KeyValuePair<St
562
567
JsonElement value ;
563
568
for (String field : fields ) {
564
569
value = json .get (field );
570
+ if (value == null ) continue ;
565
571
if (longFields .contains (field )) pair .put (field , value .getAsLong ());
566
572
else if (intFields .contains (field )) pair .put (field , value .getAsInt ());
567
- else if (value instanceof JsonPrimitive ) {
568
- JsonPrimitive primitive = value .getAsJsonPrimitive ();
569
- if (primitive .isBoolean ()) pair .put (field , JsonUtils .fromJson (value , Boolean .class ));
570
- else if (primitive .isNumber ()) pair .put (field , JsonUtils .fromJson (value , Long .class ));
571
- else pair .put (field , String .valueOf (value ));
572
- } else {
573
+ // else if (value instanceof JsonPrimitive) {
574
+ // JsonPrimitive primitive = value.getAsJsonPrimitive();
575
+ // if (primitive.isBoolean()) pair.put(field, JsonUtils.fromJson(value, Boolean.class));
576
+ // else if (primitive.isNumber()) pair.put(field, JsonUtils.fromJson(value, Long.class));
577
+ // else pair.put(field, String.valueOf(value));
578
+ // }
579
+ else {
573
580
try {
574
581
pair .put (field , JsonUtils .toString (value ));
575
582
} catch (JsonSyntaxException e ) {
0 commit comments