Esempio n. 1
0
    @Override
    public AtomicColumnType fromJsonNode(JsonNode json) {
      if (json.isObject() && json.has("value")) {
        return null;
      }
      BaseType baseType = BaseType.fromJson(json, "key");

      if (baseType != null) {

        AtomicColumnType atomicColumnType = new AtomicColumnType(baseType);

        JsonNode node = null;
        if ((node = json.get("min")) != null) {
          atomicColumnType.setMin(node.asLong());
        }

        if ((node = json.get("max")) != null) {
          if (node.isNumber()) {
            atomicColumnType.setMax(node.asLong());
          } else if ("unlimited".equals(node.asText())) {
            atomicColumnType.setMax(Long.MAX_VALUE);
          }
        }
        return atomicColumnType;
      }

      return null;
    }
Esempio n. 2
0
 protected void assertNodeNumbers(JsonNode n, int expInt, double expDouble) {
   assertEquals(expInt, n.asInt());
   assertEquals(expInt, n.asInt(-42));
   assertEquals((long) expInt, n.asLong());
   assertEquals((long) expInt, n.asLong(19L));
   assertEquals(expDouble, n.asDouble());
   assertEquals(expDouble, n.asDouble(-19.25));
 }
Esempio n. 3
0
 protected void assertNodeNumbersForNonNumeric(JsonNode n) {
   assertFalse(n.isNumber());
   assertEquals(0, n.asInt());
   assertEquals(-42, n.asInt(-42));
   assertEquals(0, n.asLong());
   assertEquals(12345678901L, n.asLong(12345678901L));
   assertEquals(0.0, n.asDouble());
   assertEquals(-19.25, n.asDouble(-19.25));
 }
 /** Parses execution options from a json object. Unrecognized elements are ignored. */
 public static ExecutionOptions fromJson(ObjectNode node) {
   ExecutionOptions ret = new ExecutionOptions();
   JsonNode x = node.get("timeLimit");
   if (x != null) {
     ret.timeLimit = x.asLong();
   }
   x = node.get("asynchronous");
   if (x != null) {
     ret.asynchronous = x.asLong();
   }
   return ret;
 }
  public Object unwrap(Object o) {

    if (o == null) {
      return null;
    }
    if (!(o instanceof JsonNode)) {
      return o;
    }

    JsonNode e = (JsonNode) o;

    if (e.isValueNode()) {

      if (e.isTextual()) {
        return e.asText();
      } else if (e.isBoolean()) {
        return e.asBoolean();
      } else if (e.isInt()) {
        return e.asInt();
      } else if (e.isLong()) {
        return e.asLong();
      } else if (e.isBigDecimal()) {
        return e.decimalValue();
      } else if (e.isDouble()) {
        return e.doubleValue();
      } else if (e.isFloat()) {
        return e.floatValue();
      } else if (e.isBigDecimal()) {
        return e.decimalValue();
      } else if (e.isNull()) {
        return null;
      }
    }
    return o;
  }
Esempio n. 6
0
    @Override
    public KeyValuedColumnType fromJsonNode(JsonNode json) {
      if (json.isValueNode() || !json.has("value")) {
        return null;
      }
      BaseType keyType = BaseType.fromJson(json, "key");
      BaseType valueType = BaseType.fromJson(json, "value");

      KeyValuedColumnType keyValueColumnType = new KeyValuedColumnType(keyType, valueType);
      JsonNode node = null;
      if ((node = json.get("min")) != null) {
        keyValueColumnType.setMin(node.asLong());
      }

      if ((node = json.get("max")) != null) {
        if (node.isLong()) {
          keyValueColumnType.setMax(node.asLong());
        } else if (node.isTextual() && "unlimited".equals(node.asText())) {
          keyValueColumnType.setMax(Long.MAX_VALUE);
        }
      }

      return keyValueColumnType;
    }
Esempio n. 7
0
  public static void firstSituation(String ok) throws IOException {

    byte[] jsonData = ok.getBytes();
    ObjectMapper objectMapper = new ObjectMapper();

    JsonNode rootNode = objectMapper.readTree(jsonData);
    JsonNode idNode = rootNode.path("id");
    System.out.println("id = " + idNode.asInt());

    JsonNode phoneNosNode = rootNode.path("phoneNumbers");
    Iterator<JsonNode> elements = phoneNosNode.elements();
    while (elements.hasNext()) {
      JsonNode phone = elements.next();
      System.out.println("phoneNumbers = " + phone.asLong());
    }
  }
 public Object extension(JsonNode jsonNode) {
   if (jsonNode.getNodeType().equals(JsonNodeType.BOOLEAN)) {
     return jsonNode.asBoolean();
   }
   if (jsonNode.getNodeType().equals(JsonNodeType.STRING)) {
     return jsonNode.asText();
   }
   if (jsonNode.getNodeType().equals(JsonNodeType.NUMBER)) {
     NumericNode n = (NumericNode) jsonNode;
     if (n.isLong()) {
       return jsonNode.asLong();
     }
     if (n.isInt()) {
       return jsonNode.asInt();
     }
     if (n.isBigDecimal()) {
       return jsonNode.textValue();
     }
     if (n.isBoolean()) {
       return jsonNode.asBoolean();
     }
     if (n.isFloat()) {
       return jsonNode.floatValue();
     }
     if (n.isDouble()) {
       return jsonNode.doubleValue();
     }
     if (n.isShort()) {
       return jsonNode.intValue();
     }
     return jsonNode.asText();
   }
   if (jsonNode.getNodeType().equals(JsonNodeType.ARRAY)) {
     ArrayNode an = (ArrayNode) jsonNode;
     List<Object> o = new ArrayList<Object>();
     for (JsonNode i : an) {
       Object obj = extension(i);
       if (obj != null) {
         o.add(obj);
       }
     }
     return o;
   }
   return jsonNode;
 }
Esempio n. 9
0
 /**
  * Parses an ID.
  *
  * @param node
  * @return
  */
 protected Object parseId(JsonNode node) {
   if (node == null || node.isNull()) {
     return null;
   } else if (node.isDouble()) {
     return node.asDouble();
   } else if (node.isFloatingPointNumber()) {
     return node.asDouble();
   } else if (node.isInt()) {
     return node.asInt();
   } else if (node.isIntegralNumber()) {
     return node.asInt();
   } else if (node.isLong()) {
     return node.asLong();
   } else if (node.isTextual()) {
     return node.asText();
   }
   throw new IllegalArgumentException("Unknown id type");
 }