Package com.google.gson

Examples of com.google.gson.JsonPrimitive


    @Override
    public JsonElement serialize(EvolutionaryProcess<AdaptiveLogisticRegression.Wrapper> x,
                                 Type type,
                                 JsonSerializationContext jsc) {
      JsonObject r = new JsonObject();
      r.add("threadCount", new JsonPrimitive(x.getThreadCount()));
      JsonArray v = new JsonArray();
      for (State<AdaptiveLogisticRegression.Wrapper> state : x.getPopulation()) {
        v.add(jsc.serialize(state, STATE_TYPE));
      }
      r.add("population", v);
View Full Code Here


  public void testSimpleDtoImpl_deserialize() {
    final String fooString = "Something";

    JsonObject json = new JsonObject();
    json.add("name", new JsonPrimitive(fooString));

    SimpleDtoImpl deserialized = SimpleDtoImpl.fromJsonElement(json);
    assertTrue(deserialized.hasName());
    assertFalse(deserialized.hasIDontStartWithGet());
    checkSimpleDto(deserialized, fooString, 0);
View Full Code Here

  public HashMap<String, JsonElement> getContent(){
    Gson gson = GsonHelper.getGson();
    JsonObject obj = gson.toJsonTree(getSelectors()).getAsJsonObject();
   
    HashMap<String, JsonElement> content = new HashMap<String,JsonElement>();
    content.put("origin", new JsonPrimitive(getOrigin()));
    if(getTransaction_id() != null)
      content.put("transaction_id", new JsonPrimitive(getTransaction_id()));
    content.put("selectors", obj);
    if(getGoogle_transaction_id() != null) {
      content.put("google_transaction_id", new JsonPrimitive(getGoogle_transaction_id()));
    }
    return content;
  }
View Full Code Here

  public HashMap<String, JsonElement> getContent() {
    Gson gson = GsonHelper.getGson();
    JsonObject obj = gson.toJsonTree(getCart()).getAsJsonObject();
   
    HashMap<String, JsonElement> content = new HashMap<String, JsonElement>();
    content.put("origin", new JsonPrimitive(getOrigin()));
    content.put("cart", obj);
    if(getTransaction_id() != null)
      content.put("transaction_id", new JsonPrimitive(getTransaction_id()));
    if(getTransaction_url() != null)
      content.put("transaction_url", new JsonPrimitive(getTransaction_url()));
    content.put("google_transaction_id", new JsonPrimitive(getGoogle_transaction_id()));
    return content;
  }
View Full Code Here

  }

  @Override
  public HashMap<String, JsonElement> getContent() {
    HashMap<String, JsonElement> content = new HashMap<String, JsonElement>();
    content.put("google_transaction_id", new JsonPrimitive(getGoogle_transaction_id()));
    content.put("status", new JsonPrimitive(getStatus()));
    if (getReason() != null)
      content.put("reason", new JsonPrimitive(getReason()));
    if (getDetailed_reason() != null)
      content.put("detailed_reason", new JsonPrimitive(getDetailed_reason()));
    return content;
  }
View Full Code Here

                    protobuf.name(entry.getKey());
                    write(entry.getValue());
                }
                protobuf.endObject();
            } else if (o instanceof JsonPrimitive) {
                JsonPrimitive json = (JsonPrimitive) o;
                if (json.isBoolean()) {
                    protobuf.value(json.getAsBoolean());
                } else if (json.isString()) {
                    protobuf.value(json.getAsString());
                } else if (json.isNumber()) {
                    Number number = json.getAsNumber();
                    if (number instanceof Double || number instanceof Float) {
                        protobuf.value(number.doubleValue());
                    } else {
                        protobuf.value(number.longValue());
                    }
                } else {
                    throw new UnsupportedOperationException("Unhandled json value: " + json.toString());
                }
            } else if (o instanceof JsonArray) {
                JsonArray json = (JsonArray) o;
                protobuf.beginArray();
                for (int i = 0; i < json.size(); i++) {
                    JsonElement jsonElement = json.get(i);
                    write(jsonElement);
                }
                protobuf.endArray();
            } else {
                throw new UnsupportedOperationException("Unhandled json type: " + o.toString());
View Full Code Here

                    continue;
                }

                InetAddress inetAddress = InetAddresses.forString(address.getIp());
                if (inetAddress instanceof Inet6Address) {
                    addresses.add(new JsonPrimitive(InetAddresses.toAddrString(inetAddress)));
                }
            }
            o.add("addresses", addresses);
            ret.add(o);
        }
View Full Code Here

    @Override
    public synchronized JsonElement serialize(Date date, Type type, JsonSerializationContext jsonSerializationContext) {
        synchronized (dateFormat) {
            String dateFormatAsString = dateFormat.format(date);
            return new JsonPrimitive(dateFormatAsString);
        }
    }
View Full Code Here

    }
   
    @Override
    public JsonElement serialize(Date t, Type type, JsonSerializationContext jsc) {
      synchronized(format) {
        return new JsonPrimitive(format.format(t));
      }
    }
View Full Code Here

      throws JsonParseException {
    final JsonElement v = a.get(idx);
    if (!v.isJsonPrimitive()) {
      throw new JsonParseException("Expected array of 4 for Edit type");
    }
    final JsonPrimitive p = (JsonPrimitive) v;
    if (!p.isNumber()) {
      throw new JsonParseException("Expected array of 4 for Edit type");
    }
    return p.getAsInt();
  }
View Full Code Here

TOP

Related Classes of com.google.gson.JsonPrimitive

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.