Package com.google.gson

Examples of com.google.gson.JsonElement


    dataService.exportData(writer);
    writer.endObject();
    writer.close();
   
    // parse the output as a JSON object for testing
    JsonElement elem = new JsonParser().parse(stringWriter.toString());
    JsonObject root = elem.getAsJsonObject();

    // make sure the root is there
    assertThat(root.has(MITREidDataService.MITREID_CONNECT_1_1), is(true));
   
    JsonObject config = root.get(MITREidDataService.MITREID_CONNECT_1_1).getAsJsonObject();
View Full Code Here


    dataService.exportData(writer);
    writer.endObject();
    writer.close();
   
    // parse the output as a JSON object for testing
    JsonElement elem = new JsonParser().parse(stringWriter.toString());
    JsonObject root = elem.getAsJsonObject();

    // make sure the root is there
    assertThat(root.has(MITREidDataService.MITREID_CONNECT_1_1), is(true));
   
    JsonObject config = root.get(MITREidDataService.MITREID_CONNECT_1_1).getAsJsonObject();
View Full Code Here

    dataService.exportData(writer);
    writer.endObject();
    writer.close();
   
    // parse the output as a JSON object for testing
    JsonElement elem = new JsonParser().parse(stringWriter.toString());
    JsonObject root = elem.getAsJsonObject();

    // make sure the root is there
    assertThat(root.has(MITREidDataService.MITREID_CONNECT_1_1), is(true));
   
    JsonObject config = root.get(MITREidDataService.MITREID_CONNECT_1_1).getAsJsonObject();
View Full Code Here

    dataService.exportData(writer);
    writer.endObject();
    writer.close();
   
    // parse the output as a JSON object for testing
    JsonElement elem = new JsonParser().parse(stringWriter.toString());
    JsonObject root = elem.getAsJsonObject();

    // make sure the root is there
    assertThat(root.has(MITREidDataService.MITREID_CONNECT_1_1), is(true));
   
    JsonObject config = root.get(MITREidDataService.MITREID_CONNECT_1_1).getAsJsonObject();
View Full Code Here

        if (new File(yiiConfigPath).exists()) {

            BufferedReader reader = execYiiLite("print json_encode(require('" + yiiConfigPath + "'));");
            if (reader != null) {
                JsonStreamParser jsonStreamParser = new JsonStreamParser(reader);
                JsonElement obj = jsonStreamParser.next();
                JsonObject root = obj.getAsJsonObject();

                if (root != null && root.has("aliases") && root.get("aliases").isJsonObject()) {
                    JsonObject aliasesObj = root.get("aliases").getAsJsonObject();
                    for (Map.Entry<String, JsonElement> el : aliasesObj.entrySet()) {
                        aliases.put(el.getKey(), el.getValue().toString());
View Full Code Here

    public HashMap<String, String> getComponentsClassMap() {
        if (componentsMap == null) {
            componentsMap = new HashMap<String, String>();
            if (components.size() > 0) {
                for (String key : components.keySet()) {
                    JsonElement el = components.get(key).getValue();
                    JsonObject elArr = el.getAsJsonObject();
                    for (Map.Entry<String, JsonElement> elArrKey : elArr.entrySet()) {
                        if (elArrKey.getKey().toLowerCase().equals("class")) {
                            String className = elArrKey.getValue().getAsString();
                            componentsMap.put(key, className);
                        }
View Full Code Here

  }

  public void shouldMapFromJsonElement() throws Exception {
    String orderJson = "{\"id\":456, \"customer\":{\"id\":789, \"street_address\":\"123 Main Street\", \"address_city\":\"SF\"}}";
    JsonParser jsonParser = new JsonParser();
    JsonElement element = jsonParser.parse(orderJson);

    Order order = modelMapper.map(element, Order.class);

    assertEquals(order.id, 456);
    assertEquals(order.customer.id, 789);
View Full Code Here

  }

  public void shouldMapWithExplicitMapping() throws Exception {
    String orderJson = "{\"id\":456, \"customer\":{\"id\":789, \"strt\":\"123 Main Street\", \"cty\":\"SF\"}}";
    JsonParser jsonParser = new JsonParser();
    JsonElement element = jsonParser.parse(orderJson);

    modelMapper.createTypeMap(element, Order.class).addMappings(
        new PropertyMap<JsonElement, Order>() {
          @Override
          protected void configure() {
View Full Code Here

    assertEquals(order.customer.address.city, "SF");
  }

  public void shouldGetElements() {
    String json = "{\"object\":{\"subkey\":\"subvalue\"}, \"array\":[\"elem1\", \"elem2\"], \"boolean\":true, \"number\":55, \"string\":\"foo\", \"null\": null}";
    JsonElement element = new JsonParser().parse(json);

    JsonObject objElem = (JsonObject) valueReader.get(element, "object");
    assertEquals(objElem.get("subkey").getAsString(), "subvalue");

    JsonArray arrayElem = (JsonArray) valueReader.get(element, "array");
View Full Code Here

*/
public class JsonElementValueReader implements ValueReader<JsonElement> {
  public Object get(JsonElement source, String memberName) {
    if (source.isJsonObject()) {
      JsonObject subjObj = source.getAsJsonObject();
      JsonElement propertyElement = subjObj.get(memberName);
      if (propertyElement == null)
        throw new IllegalArgumentException();

      if (propertyElement.isJsonObject())
        return propertyElement.getAsJsonObject();
      if (propertyElement.isJsonArray())
        return propertyElement.getAsJsonArray();
      if (propertyElement.isJsonPrimitive()) {
        JsonPrimitive jsonPrim = propertyElement.getAsJsonPrimitive();
        if (jsonPrim.isBoolean())
          return jsonPrim.getAsBoolean();
        if (jsonPrim.isNumber())
          return jsonPrim.getAsNumber();
        if (jsonPrim.isString())
View Full Code Here

TOP

Related Classes of com.google.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.