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

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


   {
      Method[] methods = object.getClass().getMethods();

      List<String> transientFields = getTransientFields(object.getClass());

      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 at least one more character and return boolean type
          * 2. Must be without parameters
          * 3. Must not be in list of skipped methods
          */

         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)
               {
View Full Code Here


            }

            return jsonArray;
         }
         case MAP :
            JsonValue jsonObject = new ObjectValue();
            Map<String, Object> map = new HashMap<String, Object>((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 :
View Full Code Here

    */
   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())
         current.addElement(o);
      values.push(current);
View Full Code Here

   public JsonValue createJsonObject(Map<String, Object> map) throws JsonException
   {
      if (map == null)
         return new NullValue();

      JsonValue jsonObject = new ObjectValue();
      Set<String> keys = map.keySet();
      for (String k : keys)
      {
         Object o = map.get(k);
         // If :
         // 1. Known types (primitive, String, array of primitive or String)
         // 2. Array of any object (expect for Java Bean)
         // 3. Collection<?>
         // 4. Map<String, ?>
         if (JsonUtils.getType(o) != null)
            jsonObject.addElement(k, createJsonValue(o));
         else
            jsonObject.addElement(k, createJsonObject(o));
      }
      return jsonObject;
   }
View Full Code Here

   {
      Method[] methods = object.getClass().getMethods();

      List<String> transientFields = getTransientFields(object.getClass());

      JsonValue jsonRootValue = new ObjectValue();

      for (Method method : methods)
      {
         String name = 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 "getClass" method;
          */
         String key = null;
         if (name.startsWith("get") && name.length() > 3 && method.getParameterTypes().length == 0
            && !"getClass".equals(name))
         {
            key = name.substring(3);
         }
         else if (name.startsWith("is") && name.length() > 2
            && (method.getReturnType() == Boolean.class || method.getReturnType() == boolean.class)
            && method.getParameterTypes().length == 0)
         {
            key = name.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 :
                  // 1. Known types (primitive, String, array of primitive or String)
                  // 2. Array of any object (expect for Java Bean)
                  // 3. Collection<?>
                  // 4. Map<String, ?>
                  if (JsonUtils.getType(invokeResult) != null)
                  {
                     jsonRootValue.addElement(key, createJsonValue(invokeResult));
                  }
                  else
                  {
                     jsonRootValue.addElement(key, createJsonObject(invokeResult));
                  }

               }
               catch (InvocationTargetException e)
               {
View Full Code Here

            }

            return jsonArray;
         }
         case MAP :
            JsonValue jsonObject = new ObjectValue();
            Map<String, Object> map = new HashMap<String, Object>((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 :
View Full Code Here

   {
      Method[] methods = object.getClass().getMethods();

      List<String> transientFields = getTransientFields(object.getClass());

      JsonValue jsonRootValue = new ObjectValue();

      for (Method method : methods)
      {
         String name = 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 "getClass" method;
          */
         String key = null;
         if (name.startsWith("get") && name.length() > 3 && method.getParameterTypes().length == 0
            && !"getClass".equals(name))
         {
            key = name.substring(3);
         }
         else if (name.startsWith("is") && name.length() > 2
            && (method.getReturnType() == Boolean.class || method.getReturnType() == boolean.class)
            && method.getParameterTypes().length == 0)
         {
            key = name.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);
View Full Code Here

            }

            return jsonArray;
         }
         case MAP :
            JsonValue jsonObject = new ObjectValue();
            Map<String, Object> map = new HashMap<String, Object>((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

   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 = new HashMap<String, Object>((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

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.