create a string (without quotes)out of the object fields that are set
@param obj Object
@return String in Json format.
@throws Exception Nitro exception is thrown.
965019
public static String object_to_string_withoutquotes(java.lang.Object obj) throws Exception {
		String str = null;

		Class<?> c = obj.getClass();
		Field[] flds = c.getDeclaredFields();
		if (flds != null) {
			for (int i = 0; i < flds.length; i++)
			{
				flds[i].setAccessible(true);
				if (flds[i].get(obj) != null)
				{
					String strtmp = "";
					if (flds[i].getType().isArray()) {
						Object tmp = flds[i].get(obj);
						if (tmp instanceof String[]) {
							String[] tmp1 = (String[])tmp;
							for (int j = 0 ;j<tmp1.length;j++) {
								strtmp += tmp1[j] + " "; 
							}
						} else if (tmp instanceof Integer[]) {
							Integer[] tmp1 = (Integer[])tmp;
							for (int j = 0 ;j<tmp1.length;j++) {
								strtmp += tmp1[j].toString() + " "; 
							}
						} else if (tmp instanceof Long[]) {
							Long[] tmp1 = (Long[])tmp;
							for (int j = 0 ;j<tmp1.length;j++) {
								strtmp += tmp1[j].toString() + " "; 
							}
						} else if (tmp instanceof Double[]) {
							Double[] tmp1 = (Double[])tmp;
							for (int j = 0 ;j<tmp1.length;j++) {
								strtmp += tmp1[j].toString() + " "; 
							}
						} else if(tmp instanceof Boolean[]) {
							Boolean[] tmp1 = (Boolean[])tmp;
							for (int j = 0 ;j<tmp1.length;j++) {
								strtmp += tmp1[j].toString() + " "; 
							}
						}						
						strtmp = strtmp.trim();
					} else {
						strtmp = flds[i].get(obj).toString();
					}
					if (str != null)
						str = str + ",";
					if (str == null)
					{
						str = flds[i].getName() + ":" + encode(strtmp);
					}
					else
					{
						str = str +flds[i].getName() + ":" + encode(strtmp);
					}
				}
			}
		}
		return str;
	}
136585
private String getMemberAsString(JsonObject obj, String memberName, String defaultValue) {
        try {
     	   JsonPrimitive value = obj.getAsJsonPrimitive(memberName);

	        if (value != null) {
	            return value.getAsString();
	        }
	        return defaultValue;
	        
        } catch (ClassCastException | IllegalStateException e) {
            throw new JsonParseException("Not a JSON string", e);
        }
    }
594364
public static <T> String marshal(T obj) throws JAXBException {
    StringWriter sw = new StringWriter();
    marshal(obj, sw);
    return sw.toString();
  }
1031963
public static String toPrettyJson(Object object){
		try {			
			return getMapper().writerWithDefaultPrettyPrinter().writeValueAsString(object);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
979035
public String toJsonString() throws Exception {
		List<?> rootContainerJsonList = (List<?>) Json.runtimeObjectToJToken(mainContentContainer);

		HashMap<String, Object> rootObject = new HashMap<String, Object>();
		rootObject.put("inkVersion", inkVersionCurrent);
		rootObject.put("root", rootContainerJsonList);

		return SimpleJson.HashMapToText(rootObject);
	}
1242556
public static <T> String serialize(T obj) {
        if (obj == null) {
            return "";
        }
        ByteArrayOutputStream bos = null;
        ObjectOutputStream oos = null;
        try {
            bos = new ByteArrayOutputStream();
            oos = new ObjectOutputStream(bos);
            oos.writeObject(obj);
            return CommonUtils.bytesToBase64Str(bos.toByteArray());
        } catch (Exception e) {
            throw new RuntimeException("serialize session error", e);
        } finally {
            CommonUtils.closeIOStream(null, bos);
            CommonUtils.closeIOStream(null, oos);
        }
    }
580822
public static Object arrayToString(final Object obj) {
        if (obj != null && obj.getClass().isArray()) {
            final int len = Array.getLength(obj);
            final String[] strings = new String[len];
            for (int i = 0; i < len; i++) {
                strings[i] = String.valueOf(Array.get(obj, i));
            }
            return Arrays.toString(strings);
        } else {
            return obj;
        }
    }
1351893
public static String getString(JsonObject object, String field, String defaultValue) {
        final JsonValue value = object.get(field);
        if (value == null || value.isNull()) {
            return defaultValue;
        } else {
            return value.asString();
        }
    }
373600
public static String toPrettyJsonString(Object object) {
        try {
            return jsonMapper.writerWithDefaultPrettyPrinter()
                    .writeValueAsString(object);
        } catch (JsonProcessingException e) {
            return JMExceptionManager.handleExceptionAndReturnNull(log, e,
                    "toPrettyJsonString", object);
        }
    }
63887
private static String jsonEncode(Object object) throws IOException {
      
      ObjectMapper mapper = new ObjectMapper();
      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      try {
         mapper.writeValue(outputStream, object);
         return new String(outputStream.toByteArray());
      } catch (JsonGenerationException e) {
         logger.severe("unable encode");
         throw new IOException(e);
      } catch (JsonMappingException e) {
         logger.severe("unable encode");
         throw new IOException(e.getMessage());
      }
      
   }
884574
public static String serialize(Object object) {
	if (object == null) return "[null]";
	try {
	    return new ScriptConverter().serialize(object);
	}
	catch (Throwable t) {
	    ExceptionUtil.rethrowIfNecessary(t);
	    return object.toString();
	}
    }
584784
public static String toJsonString(Object obj, ClassLoader classLoader) {
        if (obj == null) {
            return "null";
        }
        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
        if (classLoader != null) {
            Thread.currentThread().setContextClassLoader(classLoader);
        }
        try {
            ObjectMapper mapper = poolMapper.borrowObject();
            if (mapper != null) {
                try {
                    return mapper.writeValueAsString(obj);
                } finally {
                    poolMapper.returnObject(mapper);
                }
            }
            throw new SerializationException("No ObjectMapper instance avaialble!");
        } catch (Exception e) {
            throw e instanceof SerializationException ? (SerializationException) e
                    : new SerializationException(e);
        } finally {
            Thread.currentThread().setContextClassLoader(oldClassLoader);
        }
    }
99666
public static String stringify(ObjectMapper mapper, Object object) {
        try {
            return mapper.writeValueAsString(object);
        } catch (JsonProcessingException e) {
            throw new IllegalArgumentException(e);
        }
    }
609362
public StrBuilder append(final Object obj) {
        if (obj == null) {
            return appendNull();
        }
        if (obj instanceof CharSequence) {
            return append((CharSequence) obj);
        }
        return append(obj.toString());
    }
895476
@SuppressWarnings("PMD.AvoidCatchingThrowable")
  static String mkString(Object obj) {
    if (obj == null) {
      return "null";
    }
    try {
      return obj.toString() + " (type is " + obj.getClass() + ")";
    } catch (Throwable t) {
      return t.getClass().toString() + ": " + t.getMessage() + " (type is " + obj.getClass() + ")";
    }
  }
728167
public String from(Object obj) {
                StringBuilder sb = new StringBuilder(str);
                Method[] methods = obj.getClass().getMethods();
                Field[] fields = obj.getClass().getDeclaredFields();
                int lastIndex = -1;
                out:
                while (true) {
                        int start = sb.indexOf("${", lastIndex) + 2;
                        if (start == 1) {
                                break;
                        }
                        int end = sb.indexOf("}", start);
                        if (end == -1 || start == end) {
                                break;
                        }
                        String name = sb.substring(start, end);
                        // check functional methods
                        for (Method m : methods) {
                                String mName = m.getName();
                                if (m.getParameterTypes().length == 0 && m.getReturnType() != Void.TYPE && mName.equals(name)) {
                                        m.setAccessible(true);
                                        try {
                                                sb.replace(start - 2, end + 1, m.invoke(obj, new Object[0]).toString());
                                        } catch (Exception e) {
                                                throw $(e);
                                        }
                                        lastIndex = end;
                                        continue out;
                                }
                        }
                        // check getter
                        for (Method m : methods) {
                                String mName = m.getName();
                                if (m.getParameterTypes().length == 0 && m.getReturnType() != Void.TYPE
                                        && mName.equals("get" + name.substring(0, 1).toUpperCase() + name.substring(1))) {
                                        m.setAccessible(true);
                                        try {
                                                sb.replace(start - 2, end + 1, m.invoke(obj, new Object[0]).toString());
                                        } catch (Exception e) {
                                                throw $(e);
                                        }
                                        lastIndex = end;
                                        continue out;
                                }
                        }
                        // check field
                        for (Field f : fields) {
                                if (f.getName().equals(name)) {
                                        f.setAccessible(true);
                                        try {
                                                sb.replace(start - 2, end + 1, f.get(obj).toString());
                                        } catch (Exception e) {
                                                throw $(e);
                                        }
                                        lastIndex = end;
                                        continue out;
                                }
                        }
                        lastIndex = end;
                }
                str = sb.toString();
                return str;
        }
1060715
public static <T> byte[] serialize(T obj) {
		if (null == obj || false == (obj instanceof Serializable)) {
			return null;
		}

		FastByteArrayOutputStream byteOut = new FastByteArrayOutputStream();
		ObjectOutputStream oos = null;
		try {
			oos = new ObjectOutputStream(byteOut);
			oos.writeObject(obj);
			oos.flush();
		} catch (Exception e) {
			throw new UtilException(e);
		} finally {
			IoUtil.close(oos);
		}
		return byteOut.toByteArray();
	}