Examples of JzonElement


Examples of foodev.jsondiff.jsonwrap.JzonElement

    JzonObject patch = (JzonObject) patchEl;
    Set<Entry<String, JzonElement>> memb = new TreeSet<Entry<String, JzonElement>>(INSTRUCTIONS_COMPARATOR);
    memb.addAll(patch.entrySet());
    for (Entry<String, JzonElement> entry : memb) {
      String key = entry.getKey();
      JzonElement value = entry.getValue();
      if (key.startsWith(MOD)) {
        JzonElement partialInstructions = entry.getValue();
        if (!partialInstructions.isJsonArray()) {
          throw new IllegalArgumentException();
        }
        JzonArray array = (JzonArray) partialInstructions;
        JzonElement applyTo;
        if (key.equals(MOD)) {
          applyTo = origEl;
        } else if (origEl.isJsonArray()) {
          int index = Integer.parseInt(key.substring(1));
          applyTo = ((JzonArray) origEl).get(index);
        } else {
          applyTo = ((JzonObject) origEl).get(key.substring(1));
        }
        for (int i = 0; i < array.size(); i++) {
          JzonElement partial = array.get(i);
          if (!partial.isJsonObject()) {
            throw new IllegalArgumentException();
          }
          Entry<String, JzonElement> childentry = ((JzonObject) partial).entrySet().iterator().next();
          String childKey = childentry.getKey();
          Instruction instruction = create(childKey);
          boolean newAppliance = false;
          if (instruction.isIndexed() && !applyTo.isJsonArray()) {
            applyTo = factory.createJsonArray();
            newAppliance = true;
          } else if (!instruction.isIndexed() && !applyTo.isJsonObject()) {
            applyTo = factory.createJsonObject();
            newAppliance = true;
          }
          if (newAppliance) {
            if (origEl.isJsonArray()) {
              int index = Integer.parseInt(key);
              ((JzonArray) origEl).insert(index, applyTo);
            } else {
              ((JzonObject) origEl).add(key.substring(1), applyTo);
            }
          }
          applyPartial(applyTo, instruction, childentry.getValue());
        }
      } else {
        Instruction instruction = create(key);
        if (instruction.oper == Oper.INSERT || instruction.oper == Oper.DELETE) {
          applyPartial(origEl, instruction, value);
        } else if (instruction.isIndexed()) {
          if (!origEl.isJsonArray()) {
            throw new IllegalArgumentException();
          }
          if (value.isJsonPrimitive()) {
            ((JzonArray) origEl).set(instruction.index, value);
          } else {
            if (((JzonArray) origEl).size() <= instruction.index) {
              throw new IllegalArgumentException("Wrong index " + instruction.index + " for " + origEl);
            }
            JzonElement childEl = ((JzonArray) origEl).get(instruction.index);
            apply(childEl, value);
          }
        } else if (origEl.isJsonObject()) {
          if (value.isJsonPrimitive() || value.isJsonNull()) {
            ((JzonObject) origEl).add(key, value);
          } else {
            JzonElement childEl = ((JzonObject) origEl).get(key);
            apply(childEl, value);
          }
        } else {
          throw new IllegalArgumentException();
        }
View Full Code Here

Examples of foodev.jsondiff.jsonwrap.JzonElement

   * @throws IllegalArgumentException
   *             if the given arguments are not accepted.
   */
  public void apply(Object orig, Object patch) {

    JzonElement origEl = factory.wrap(orig);
    JzonElement patchEl = factory.wrap(patch);

    apply(origEl, patchEl);

  }
View Full Code Here

Examples of foodev.jsondiff.jsonwrap.JzonElement

   *             if the strings can't be parsed as JSON.
   */
  public String apply(String orig, String patch) throws IllegalArgumentException {

    // by providing null as hint we default to GSON.
    JzonElement origEl = factory.parse(orig);
    JzonElement patchEl = factory.parse(patch);

    apply(origEl, patchEl);

    return origEl.toString();

View Full Code Here

Examples of foodev.jsondiff.jsonwrap.JzonElement

   * @throws IllegalArgumentException
   *             if the given arguments are not accepted.
   */
  public Object diff(Object from, Object to) throws IllegalArgumentException {

    JzonElement fromEl = factory.wrap(from);
    JzonElement toEl = factory.wrap(to);

    JzonObject diff = diff(fromEl, toEl);

    return diff.unwrap();
  }
View Full Code Here

Examples of foodev.jsondiff.jsonwrap.JzonElement

   * @throws JsonWrapperException
   *             if the strings can't be parsed as JSON.
   */
  public String diff(String from, String to) throws IllegalArgumentException {

    JzonElement fromEl = factory.parse(from);
    JzonElement toEl = factory.parse(to);

    return diff(fromEl, toEl).toString();

  }
View Full Code Here

Examples of foodev.jsondiff.jsonwrap.JzonElement

        HashSet<Entry<String, JzonElement>> jset = new HashSet<Entry<String, JzonElement>>();

        for (final Entry<String, JsonElement> e : set) {

            final JzonElement el = GsonWrapper.wrap(e.getValue());

            jset.add(new Entry<String, JzonElement>() {

                @Override
                public String getKey() {
View Full Code Here

Examples of foodev.jsondiff.jsonwrap.JzonElement

        for (Iterator<Entry<String, JsonNode>> i = wrapped.getFields(); i.hasNext();) {

            final Entry<String, JsonNode> e = i.next();

            final JzonElement el = JacksonWrapper.wrap(e.getValue());

            jset.add(new Entry<String, JzonElement>() {

                @Override
                public String getKey() {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.