public static OtpErlangObject fromJava(Object o) throws IllegalArgumentException {

        if (o instanceof String) {
            return new OtpErlangAtom((String) o);
        } else if (o instanceof Boolean) {
            return (o == Boolean.TRUE) ? new OtpErlangAtom("true") : new OtpErlangAtom("false");
        } else if (o instanceof byte[]) {
            return new OtpErlangBinary((byte[]) o);
        } else if (o instanceof Integer) {
            return new OtpErlangInt(((Integer) o).intValue());
        } else if (o instanceof Long) {
            return new OtpErlangInt(((Long) o).intValue());
        } else if (o instanceof Double) {
            return new OtpErlangDouble(((Double) o).doubleValue());
        } else if (o instanceof List) {
            Object[] list = ((List) o).toArray();
            OtpErlangObject[] erlObjects = new OtpErlangObject[list.length];
            for (int i = 0; i < list.length; i++) {
                erlObjects[i] = (OtpErlangObject) list[i];
            }
            return new OtpErlangList(erlObjects);
        }

        throw new IllegalArgumentException("cannot transform input class: " + o.getClass().getName());
    }