Package org.codehaus.jackson.node

Examples of org.codehaus.jackson.node.ObjectNode


        addHeader("WWW-Authenticate", "OAuth");
        return renderJSON(obj, UNAUTHORIZED);
    }

    protected Result renderForbidden() {
        ObjectNode obj = new ObjectNode(JsonNodeFactory.instance);
        obj.put("result", "forbidden");
        obj.put("reason", "forbidden action");

        return renderJSON(obj, FORBIDDEN);
    }
View Full Code Here


    return query;
  }

  @Override
  ObjectNode toJson() {
    final ObjectNode obj = mapper.createObjectNode();
    final ObjectNode twig = obj.putObject(TwigPropertyParser.TWIG_PROPERTY);

    if (hasRoot) {
      twig.put(RootPropertyParser.ROOT_PROPERTY, rootBooleanExpression);
    }

    if (this.hasLevel()) {
      twig.put(LevelPropertyParser.LEVEL_PROPERTY, this.getLevel());
    }

    if (this.hasRange()) {
      final ArrayNode array = twig.putArray(RangePropertyParser.RANGE_PROPERTY);
      array.add(this.getLowerBound());
      array.add(this.getUpperBound());
    }

    if (this.hasBoost()) {
      twig.put(BoostPropertyParser.BOOST_PROPERTY, this.getBoost());
    }

    ArrayNode childArray = null;
    ArrayNode descendantArray = null;
    for (final QueryClause clause : clauses) {
      if (clause instanceof BasicQueryClause) {
        if (!twig.has(ChildPropertyParser.CHILD_PROPERTY)) { // avoid to create an empty array in the JSON
          childArray = twig.putArray(ChildPropertyParser.CHILD_PROPERTY);
        }
        final ObjectNode e = childArray.addObject();
        e.put(OccurPropertyParser.OCCUR_PROPERTY, clause.getOccur().toString());
        e.putAll(clause.getQuery().toJson());
      }
      else {
        if (!twig.has(DescendantPropertyParser.DESCENDANT_PROPERTY)) { // avoid to create an empty array in the JSON
          descendantArray = twig.putArray(DescendantPropertyParser.DESCENDANT_PROPERTY);
        }
        final ObjectNode e = descendantArray.addObject();
        e.put(OccurPropertyParser.OCCUR_PROPERTY, clause.getOccur().toString());
        e.put(LevelPropertyParser.LEVEL_PROPERTY, ((DescendantQueryClause) clause).getLevel());
        e.putAll(clause.getQuery().toJson());
      }
    }

    return obj;
  }
View Full Code Here

   * @throws IllegalArgumentException If the created query object cannot be
   * converted to JSON.
   */
  @Override
  public String toString() {
    final ObjectNode node = this.toJson();
    try {
      return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(node);
    }
    catch (final Exception e) {
      throw new IllegalArgumentException(e);
View Full Code Here

    return query;
  }

  @Override
  ObjectNode toJson() {
    final ObjectNode obj = mapper.createObjectNode();
    final ObjectNode node = obj.putObject(NodePropertyParser.NODE_PROPERTY);
    node.put(QueryPropertyParser.QUERY_PROPERTY, booleanExpression);
    if (this.hasLevel()) {
      node.put(LevelPropertyParser.LEVEL_PROPERTY, this.getLevel());
    }
    if (this.hasRange()) {
      final ArrayNode array = node.putArray(RangePropertyParser.RANGE_PROPERTY);
      array.add(this.getLowerBound());
      array.add(this.getUpperBound());
    }
    if (this.hasBoost()) {
      node.put(BoostPropertyParser.BOOST_PROPERTY, this.getBoost());
    }
    return obj;
  }
View Full Code Here

    return query;
  }

  @Override
  ObjectNode toJson() {
    final ObjectNode obj = mapper.createObjectNode();
    final ArrayNode bool = obj.putArray(BooleanPropertyParser.BOOLEAN_PROPERTY);

    for (final QueryClause clause : clauses) {
      final ObjectNode e = bool.addObject();
      e.put(OccurPropertyParser.OCCUR_PROPERTY, clause.getOccur().toString());
      e.putAll(clause.getQuery().toJson());
    }

    return obj;
  }
View Full Code Here

      node.remove("Website");
    }
  }

  private void convertDeviceOwnerWebsite(final JsonNode obj) {
    final ObjectNode node = (ObjectNode) obj.path("DeviceOwner");
    final JsonNode current = node.path("Website");
    if (!current.isMissingNode() && !current.isNull()) {
      node.put("Website", this.createValueDatatype("uri", current.asText()));
    }
    if (current.isNull()) {
      node.remove("Website");
    }
  }
View Full Code Here

      node.remove("Website");
    }
  }

  private JsonNode createValueDatatype(final String datatype, final String value) {
    final ObjectNode node = mapper.createObjectNode();
    node.put(JsonTokenizer.DATATYPE_LABEL, datatype);
    node.put(JsonTokenizer.DATATYPE_VALUES, value);
    return node;
  }
View Full Code Here

  }

  private void convertRatedOutputkW(final JsonNode obj) {
    final Iterator<JsonNode> nodes = obj.path("Connector").iterator();
    while (nodes.hasNext()) {
      final ObjectNode node = (ObjectNode) nodes.next();
      final JsonNode current = node.path("RatedOutputkW");
      if (!current.isMissingNode() && !current.isNull()) {
        final double value = Double.parseDouble(current.asText());
        node.put("RatedOutputkW", value);
      }
      if (current.isNull()) {
        node.remove("RatedOutputkW");
      }
    }
  }
View Full Code Here

  }

  private void convertRatedOutputVoltage(final JsonNode obj) {
    final Iterator<JsonNode> nodes = obj.path("Connector").iterator();
    while (nodes.hasNext()) {
      final ObjectNode node = (ObjectNode) nodes.next();
      final JsonNode current = node.path("RatedOutputVoltage");
      if (!current.isMissingNode() && !current.isNull()) {
        final int value = Integer.parseInt(current.asText());
        node.put("RatedOutputVoltage", value);
      }
      if (current.isNull()) {
        node.remove("RatedOutputVoltage");
      }
    }
  }
View Full Code Here

  }

  private void convertRatedOutputCurrent(final JsonNode obj) {
    final Iterator<JsonNode> nodes = obj.path("Connector").iterator();
    while (nodes.hasNext()) {
      final ObjectNode node = (ObjectNode) nodes.next();
      final JsonNode current = node.path("RatedOutputCurrent");
      if (!current.isMissingNode() && !current.isNull()) {
        final int value = Integer.parseInt(current.asText());
        node.put("RatedOutputCurrent", value);
      }
      if (current.isNull()) {
        node.remove("RatedOutputCurrent");
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.codehaus.jackson.node.ObjectNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.