Code example for JsonArray

Methods: add

0
 
  /** 
   * Faithfully serializes a 64-bit long value as a two-number array. 
   */ 
  public static JsonArray toJson(long value) {
    JsonArray arr = new JsonArray();
    arr.add(new JsonPrimitive(JsonLongHelper.getLowWord(value)));
    arr.add(new JsonPrimitive(JsonLongHelper.getHighWord(value)));
    return arr;
  } 
 
  /** 
   * Deserializes a two-number array from {@link #toJson(long)} into a long. 
   */ 
  public static long fromJson(JsonElement e) {
    JsonArray arr = e.getAsJsonArray();
    return JsonLongHelper.toLong(arr.get(1).getAsInt(), arr.get(0).getAsInt());
  } 
 
  private GsonUtil() { 
Experience pair programming with AI  Get Codota for Java