Package org.exoplatform.ws.frameworks.json.value.impl

Examples of org.exoplatform.ws.frameworks.json.value.impl.ObjectValue


    */
   public void startObject()
   {
      if (current == null)
      {
         current = new ObjectValue();
         values.push(current);
         return;
      }
      ObjectValue o = new ObjectValue();
      if (current.isObject())
      {
         current.addElement(key, o);
      }
      else if (current.isArray())
View Full Code Here


   public JsonValue createJsonObject(Object object) throws JsonException
   {
      Class<?> clazz = object.getClass();
      Method[] methods = clazz.getMethods();
      Set<String> transientFields = getTransientFields(clazz);
      JsonValue jsonRootValue = new ObjectValue();
      for (Method method : methods)
      {
         String methodName = method.getName();
         /*
          * Method must be as follow:
          * 1. Name starts from "get" plus at least one character or
          * starts from "is" plus one more character and return boolean type;
          * 2. Must be without parameters;
          * 3. Not be in SKIP_METHODS set.
          */
         String key = null;
         if (!SKIP_METHODS.contains(methodName) && method.getParameterTypes().length == 0)
         {
            if (methodName.startsWith("get") && methodName.length() > 3)
            {
               key = methodName.substring(3);
            }
            else if (methodName.startsWith("is") && methodName.length() > 2
               && (method.getReturnType() == Boolean.class || method.getReturnType() == boolean.class))
            {
               key = methodName.substring(2);
            }
         }
         if (key != null)
         {
            // First letter of key to lower case.
            key = (key.length() > 1) ? Character.toLowerCase(key.charAt(0)) + key.substring(1) : key.toLowerCase();
            // Check is this field in list of transient field.
            if (!transientFields.contains(key))
            {
               try
               {
                  // Get result of invoke method get...
                  Object invokeResult = method.invoke(object, new Object[0]);
                  if (JsonUtils.getType(invokeResult) != null)
                  {
                     jsonRootValue.addElement(key, createJsonValue(invokeResult));
                  }
                  else
                  {
                     jsonRootValue.addElement(key, createJsonObject(invokeResult));
                  }
               }
               catch (InvocationTargetException e)
               {
                  throw new JsonException(e.getMessage(), e);
View Full Code Here

               }
            }
            return jsonArray;
         }
         case MAP :
            JsonValue jsonObject = new ObjectValue();
           
            Map<String, Object> map = (Map<String, Object>)object;
            Set<String> keys = map.keySet();
            for (String k : keys)
            {
               Object o = map.get(k);
               if (JsonUtils.getType(o) != null)
               {
                  jsonObject.addElement(k, createJsonValue(o));
               }
               else
               {
                  jsonObject.addElement(k, createJsonObject(o));
               }
            }
            return jsonObject;
         default :
            // Must not be here!
View Full Code Here

   @SuppressWarnings("unchecked")
   public void testRestoreGroovyBean() throws Exception
   {
      GroovyClassLoader cl = new GroovyClassLoader();
      Class c = cl.parseClass(Thread.currentThread().getContextClassLoader().getResourceAsStream("SimpleBean.groovy"));
      JsonValue ov = new ObjectValue();
      StringValue sv = new StringValue("test restore groovy bean");
      ov.addElement("value", sv);
      assertEquals("test restore groovy bean", ObjectBuilder.createObject(c, ov).toString());
   }
View Full Code Here

      ArrayValue exp = new ArrayValue();
      exp.addElement(new DoubleValue(1.0D));
      exp.addElement(new StringValue("to be or not to be"));
      exp.addElement(new LongValue(111));
      exp.addElement(new BooleanValue(true));
      ObjectValue o = new ObjectValue();
      o.addElement("foo", new StringValue("bar"));
      ObjectValue o1 = new ObjectValue();
      o1.addElement("object", o);
      exp.addElement(o1);

      Iterator<JsonValue> elements = jsonValue.getElements();
      Iterator<JsonValue> expElements = jsonValue.getElements();
      for (; elements.hasNext() && expElements.hasNext();)
View Full Code Here

TOP

Related Classes of org.exoplatform.ws.frameworks.json.value.impl.ObjectValue

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.