Package com.google.gson

Examples of com.google.gson.JsonElement


    JsonElement jsonElement = eval(propPath);
    return jsonElement.getAsLong();
  }
 
  public Number getAsNumber(String propPath) {
    JsonElement jsonElement = eval(propPath);
    return jsonElement.getAsNumber();
  }
View Full Code Here


    JsonElement jsonElement = eval(propPath);
    return jsonElement.getAsNumber();
  }
 
  public short getAsShort(String propPath) {
    JsonElement jsonElement = eval(propPath);
    return jsonElement.getAsShort();
  }
View Full Code Here

    JsonElement jsonElement = eval(propPath);
    return jsonElement.getAsShort();
  }
 
  public String getAsString(String propPath) {
    JsonElement jsonElement = eval(propPath);
    return jsonElement.getAsString();
  }
View Full Code Here

    JsonElement jsonElement = eval(propPath);
    return jsonElement.getAsString();
  }
 
  public boolean isBoolean(String propPath) {
    JsonElement jsonElement = eval(propPath);
    if(jsonElement instanceof JsonPrimitive)
      return ((JsonPrimitive)jsonElement).isBoolean();
   
    return false;
  }
View Full Code Here

   
    return false;
  }
 
  public boolean isNumber(String propPath) {
    JsonElement jsonElement = eval(propPath);
   
    if(jsonElement instanceof JsonPrimitive)
      return ((JsonPrimitive)jsonElement).isNumber();
    return false;
  }
View Full Code Here

      return ((JsonPrimitive)jsonElement).isNumber();
    return false;
  }
 
  public boolean isString(String propPath) {
    JsonElement jsonElement = eval(propPath);
   
    if(jsonElement instanceof JsonPrimitive)
      return ((JsonPrimitive)jsonElement).isString();
    return false;
  }
View Full Code Here

   *     -:  property expression can not be resolved
   *     :  match to a null JSON object
   *     1+  :  matched, for array element, the count of the elements inside the array
   */
  public int getMatchCount(String propPath) {
    JsonElement jsonElement = tryEval(propPath);
    if(jsonElement == null)
      return -1;
   
    if(jsonElement.isJsonNull())
      return 0;
   
    if(jsonElement.isJsonArray())
      return ((JsonArray)jsonElement).size();
   
    return 1;
  }
View Full Code Here

   
    return 1;
  }
 
  public JsonElement eval(String propPath) {
    JsonElement jsonElement = tryEval(propPath);
    if(jsonElement == null)
      throw new InternalErrorException("Property " + propPath + " is resolved to null JSON element on object: " + _json.toString());

    return jsonElement;
  }
View Full Code Here

          } else {
            resolverChain.add(new PropertyResolver(token));
          }
    }
   
    JsonElement jsonElementToResolveAt = _json;
    for(Resolver resolver : resolverChain) {
      jsonElementToResolveAt = resolver.resolve(jsonElementToResolveAt);
     
      if(jsonElementToResolveAt == null)
        break;
View Full Code Here

public class JsonAccessorTestCase extends BaseTestCase {
    protected final static Logger logger = Logger.getLogger(UtilTestCase.class);
 
    public void testJsonAccessor() {
      JsonParser parser = new JsonParser();
      JsonElement json = parser.parse("{firstName: 'Kelven', lastName: 'Yang', arrayObj: [{name: 'elem1'}, {name: 'elem2'}]}");
      JsonAccessor jsonAccessor = new JsonAccessor(json);
     
      Assert.assertTrue("Kelven".equals(jsonAccessor.getAsString("firstName")));
      Assert.assertTrue("Kelven".equals(jsonAccessor.getAsString("this.firstName")));
      Assert.assertTrue("Yang".equals(jsonAccessor.getAsString("lastName")));
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.