Package com.massivecraft.mcore.xlib.gson

Examples of com.massivecraft.mcore.xlib.gson.JsonElement


      boolean hasComplexKeys = false;
      List<JsonElement> keys = new ArrayList<JsonElement>(map.size());

      List<V> values = new ArrayList<V>(map.size());
      for (Map.Entry<K, V> entry : map.entrySet()) {
        JsonElement keyElement = toJsonTree(keyTypeAdapter, entry.getKey());
        keys.add(keyElement);
        values.add(entry.getValue());
        hasComplexKeys |= keyElement.isJsonArray() || keyElement.isJsonObject();
      }

      if (hasComplexKeys) {
        out.beginArray();
        for (int i = 0; i < keys.size(); i++) {
          out.beginArray(); // entry array
          Streams.write(keys.get(i), out);
          valueTypeAdapter.write(out, values.get(i));
          out.endArray();
        }
        out.endArray();
      } else {
        out.beginObject();
        for (int i = 0; i < keys.size(); i++) {
          JsonElement keyElement = keys.get(i);
          out.name(keyToString(keyElement));
          valueTypeAdapter.write(out, values.get(i));
        }
        out.endObject();
      }
View Full Code Here


      }
      pendingName = null;
    } else if (stack.isEmpty()) {
      product = value;
    } else {
      JsonElement element = peek();
      if (element instanceof JsonArray) {
        ((JsonArray) element).add(value);
      } else {
        throw new IllegalStateException();
      }
View Full Code Here

  @Override public JsonWriter endArray() throws IOException {
    if (stack.isEmpty() || pendingName != null) {
      throw new IllegalStateException();
    }
    JsonElement element = peek();
    if (element instanceof JsonArray) {
      stack.remove(stack.size() - 1);
      return this;
    }
    throw new IllegalStateException();
View Full Code Here

  @Override public JsonWriter endObject() throws IOException {
    if (stack.isEmpty() || pendingName != null) {
      throw new IllegalStateException();
    }
    JsonElement element = peek();
    if (element instanceof JsonObject) {
      stack.remove(stack.size() - 1);
      return this;
    }
    throw new IllegalStateException();
View Full Code Here

  @Override public JsonWriter name(String name) throws IOException {
    if (stack.isEmpty() || pendingName != null) {
      throw new IllegalStateException();
    }
    JsonElement element = peek();
    if (element instanceof JsonObject) {
      pendingName = name;
      return this;
    }
    throw new IllegalStateException();
View Full Code Here

    {
      // Old Faction LazyLocation
      for (Entry<String, JsonElement> entry : jsonObject.entrySet())
      {
        final String key = entry.getKey();
        final JsonElement value = entry.getValue();
       
        switch(key)
        {
          case "world":
            builder.world(value.getAsString());
          break;
          case "x":
            builder.locationX(value.getAsDouble());
          break;
          case "y":
            builder.locationY(value.getAsDouble());
          break;
          case "z":
            builder.locationZ(value.getAsDouble());
          break;
          case "pitch":
            builder.pitch(value.getAsFloat());
          break;
          case "yaw":
            builder.yaw(value.getAsFloat());
          break;
        }
      }
    }
    else
    {
      // The Standard Format
      for (Entry<String, JsonElement> entry : jsonObject.entrySet())
      {
        final String key = entry.getKey();
        final JsonElement value = entry.getValue();
       
        switch(key)
        {
          case NAME_SERIALIZED_WORLD:
            builder.world(value.getAsString());
          break;
          case NAME_SERIALIZED_BLOCKX:
            builder.blockX(value.getAsInt());
          break;
          case NAME_SERIALIZED_BLOCKY:
            builder.blockY(value.getAsInt());
          break;
          case NAME_SERIALIZED_BLOCKZ:
            builder.blockZ(value.getAsInt());
          break;
          case NAME_SERIALIZED_LOCATIONX:
            builder.locationX(value.getAsDouble());
          break;
          case NAME_SERIALIZED_LOCATIONY:
            builder.locationY(value.getAsDouble());
          break;
          case NAME_SERIALIZED_LOCATIONZ:
            builder.locationZ(value.getAsDouble());
          break;
          case NAME_SERIALIZED_CHUNKX:
            builder.chunkX(value.getAsInt());
          break;
          case NAME_SERIALIZED_CHUNKZ:
            builder.chunkZ(value.getAsInt());
          break;
          case NAME_SERIALIZED_PITCH:
            builder.pitch(value.getAsFloat());
          break;
          case NAME_SERIALIZED_YAW:
            builder.yaw(value.getAsFloat());
          break;
          case NAME_SERIALIZED_VELOCITYX:
            builder.velocityX(value.getAsDouble());
          break;
          case NAME_SERIALIZED_VELOCITYY:
            builder.velocityY(value.getAsDouble());
          break;
          case NAME_SERIALIZED_VELOCITYZ:
            builder.velocityZ(value.getAsDouble());
          break;
        }
      }
    }
   
View Full Code Here

  @Override public T read(JsonReader in) throws IOException {
    if (deserializer == null) {
      return delegate().read(in);
    }
    JsonElement value = Streams.parse(in);
    if (value.isJsonNull()) {
      return null;
    }
    return deserializer.deserialize(value, typeToken.getType(), gson.deserializationContext);
  }
View Full Code Here

    }
    if (value == null) {
      out.nullValue();
      return;
    }
    JsonElement tree = serializer.serialize(value, typeToken.getType(), gson.serializationContext);
    Streams.write(tree, out);
  }
View Full Code Here

   * @param memberName name of the member that is being requested.
   * @return the member matching the name. Null if no such member exists.
   */
  public JsonElement get(String memberName) {
    if (members.containsKey(memberName)) {
      JsonElement member = members.get(memberName);
      return member == null ? JsonNull.INSTANCE : member;
    }
    return null;
  }
View Full Code Here

    JsonObject in = inElement.getAsJsonObject();
    BasicDBObject out = new BasicDBObject();
    for (Entry<String, JsonElement> entry : in.entrySet())
    {
      String key = gson2MongoKey(entry.getKey());
      JsonElement val = entry.getValue();
      if (val.isJsonArray())
      {
        out.put(key, gson2MongoArray(val));
      }
      else if (val.isJsonObject())
      {
        out.put(key, gson2MongoObject(val));
      }
      else
      {
View Full Code Here

TOP

Related Classes of com.massivecraft.mcore.xlib.gson.JsonElement

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.