Converts a Java object to a srec value.

@param o The Java object
@return The srec value
191158
public static Value convertFromJava(Object o) {
        if (o instanceof Long) {
            return new NumberValue(new BigDecimal((Long) o));
        } else if (o instanceof Integer) {
            return new NumberValue(new BigDecimal((Integer) o));
        } else if (o instanceof Double) {
            return new NumberValue(new BigDecimal((Double) o));
        } else if (o instanceof Float) {
            return new NumberValue(new BigDecimal((Float) o));
        } else if (o instanceof String) {
            return new StringValue((String) o);
        } else if (o instanceof Date) {
            return new DateValue((Date) o);
        } else if (o instanceof Boolean) {
            return BooleanValue.getInstance((Boolean) o);
        } else if (o == null) {
            return NilValue.getInstance();
        }
        throw new CommandExecutionException("Could not convert Java object " + o + " to an equivalent srec value");
    }
768104
public Object convertValueToObject(ValueConverter vconv) {
    	if (valueAsJava==null) {
    		valueAsJava=vconv.convertToJava(getType(), (String)value);
    	}
        return valueAsJava;
    }
543226
public static String serialize(Serializable o) throws IOException {
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	serialize(o, baos);
	return Base64Coder.encode(baos.toByteArray());
    }
1249217
private V8Object convertJavaObject(Object o) {
		V8Object v8o = new V8Object(runtime);
		Method[] methods = o.getClass().getMethods();
		for (Method m : methods) {
			v8o.registerJavaMethod(o, m.getName(), m.getName(),
					m.getParameterTypes());
		}
		return v8o;
	}
769946
public static JsonValue serializeAsJson(Object o) throws IOException {
        try {
            return findFieldsToSerialize(o).mainObject;
        } catch (IllegalStateException ise) {
            // the reflective attempt to build the object failed.
            throw new IOException("Unable to build JSON for Object", ise);
        } catch (JsonException e) {
            throw new IOException("Unable to build JSON for Object", e);
        }
    }
254500
public Object encode(final Class c, final Object o) {
        return getEncoder(c).encode(o);
    }
17093
public static String printToStr(Object o) {
		StringWriter sw=new StringWriter();
		try {
			print(o,sw,false);
		} catch (IOException e) {
			sw.write("<<error>>");
		}
		return sw.toString().trim();
	}
1177557
public int compareTo(Object o)
    {
        if (o instanceof ServletHolder)
        {
            ServletHolder sh= (ServletHolder)o;
            if (sh==this)
                return 0;
            if (sh._initOrder<_initOrder)
                return 1;
            if (sh._initOrder>_initOrder)
                return -1;
            int c=_className.compareTo(sh._className);
            if (c==0)
                c=_name.compareTo(sh._name);
            if (c==0)
                c=this.hashCode()>o.hashCode()?1:-1;
            return c;
        }
        return 1;
    }
521619
public static String serializeAsString(Object o) throws IOException {
        try {
            JsonStructure builtJsonObject = findFieldsToSerialize(o).mainObject;
            return builtJsonObject.toString();
        } catch (IllegalStateException ise) {
            // the reflective attempt to build the object failed.
            throw new IOException("Unable to build JSON for Object", ise);
        } catch (JsonException e) {
            throw new IOException("Unable to build JSON for Object", e);
        }
    }
854219
public String toJson(Object o) {
		try {
			String json = objectMapper.writeValueAsString(o);
			LOG.debug(json);
			return json;
		} catch (Exception e) {
			throw Exceptions.propagate(e);
		}
	}
1033405
public static Object serializeAndDeserialize(Object o) throws IOException,
			ClassNotFoundException {
		ByteArrayOutputStream bytes = new ByteArrayOutputStream();
		ObjectOutputStream out = new ObjectOutputStream(bytes);
		try {
			out.writeObject(o);
		} finally {
			out.close();
		}

		ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(
				bytes.toByteArray()));
		try {
			Object result = in.readObject();
			return result;
		} finally {
			in.close();
		}
	}
56706
@SuppressWarnings("unchecked")
	private Map<String, Object> o(Object obj) {
		return (Map<String, Object>) obj;
	}
871512
public static Object OPAQUE(Object o) {
	if (o == null) return null;

	try {

	    byte[] bytes = Caster.toBytes(Reflector.callMethod(o, "getBytes", ZERO_ARGS), null);
	    return new String(bytes, "UTF-8");
	}
	catch (Exception e) {
	    // print.printST(e);
	}

	return o;
    }
899533
public static byte toByteValue(Object o, byte defaultValue) {
	if (o instanceof Byte) return ((Byte) o).byteValue();
	if (o instanceof Character) return (byte) (((Character) o).charValue());
	else if (o instanceof Boolean) return (byte) ((((Boolean) o).booleanValue()) ? 1 : 0);
	else if (o instanceof Number) return (((Number) o).byteValue());
	else if (o instanceof String) return (byte) toDoubleValue(o.toString(), defaultValue);
	else if (o instanceof ObjectWrap) {
	    return toByteValue(((ObjectWrap) o).getEmbededObject(toByte(defaultValue)), defaultValue);
	}
	return defaultValue;
    }
418188
public static byte[] objectToBytes(Object object) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream os = new ObjectOutputStream(baos);
    os.writeObject(object);
    return baos.toByteArray();
  }
622028
public static String getJarHome(Object o)
    {
        String path = o.getClass().getProtectionDomain()
                    .getCodeSource().getLocation().getFile();
        File jarFile = new File(path);
        return jarFile.getParentFile().getAbsolutePath();
    }
367577
public static String toJSONString(Object o) {
    try {
      return objectMapper.writer().without(SerializationFeature.INDENT_OUTPUT).writeValueAsString(o);
    } catch (JsonProcessingException e) {
      throw new RuntimeException(e);
    }
  }