private static String prettyPrintObject()

in src/main/java/com/amazonaws/services/simpleworkflow/flow/common/WorkflowExecutionUtils.java [801:914]


    private static String prettyPrintObject(Object object, String methodToSkip, boolean skipNullsAndEmptyCollections,
            String indentation, boolean skipLevel) {
        StringBuffer result = new StringBuffer();
        if (object == null) {
            return "null";
        }
        Class<? extends Object> clz = object.getClass();
        if (Number.class.isAssignableFrom(clz)) {
            return String.valueOf(object);
        }
        if (Boolean.class.isAssignableFrom(clz)) {
            return String.valueOf(object);
        }
        if (clz.equals(String.class)) {
            return (String) object;
        }
        if (clz.equals(Date.class) || clz.equals(Instant.class)) {
            return String.valueOf(object);
        }
        if (Map.class.isAssignableFrom(clz)) {
            return String.valueOf(object);
        }
        if (Collection.class.isAssignableFrom(clz)) {
            return String.valueOf(object);
        }

        if (!skipLevel) {
            result.append(" {");
        }
        if (object instanceof Decision.Builder) {
            result = new StringBuffer();
        }
        Method[] eventMethods = object.getClass().getMethods();
        Arrays.sort(eventMethods, Comparator.comparing(Method::getName));
        boolean first = true;
        for (Method method : eventMethods) {
            String name = method.getName();
            boolean isNotBuilder = !name.contains("toBuilder") || !method.getReturnType().equals(
                CopyableBuilder.class); //ignore methods other than builder in AWSSDK-v2
            if ((!name.startsWith("get") || name.startsWith("getValueForField")) && isNotBuilder) {
                continue;
            }
            if (name.equals(methodToSkip) || name.equals("getClass")) {
                continue;
            }
            if (Modifier.isStatic(method.getModifiers())) {
                continue;
            }
            Object value;
            try {
                if (!method.isAccessible()) {
                    method.setAccessible(true);
                }
                value = method.invoke(object, (Object[]) null);
                if (value != null && value.getClass().equals(String.class) && name.equals("getDetails")) {
                    value = printDetails((String) value);
                }
            } catch (InvocationTargetException e) {
                throw new RuntimeException(e.getTargetException());
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            if (skipNullsAndEmptyCollections) {
                if (value == null) {
                    continue;
                }
                if (value instanceof Map && ((Map<?, ?>) value).isEmpty()) {
                    continue;
                }
                if (value instanceof Collection && ((Collection<?>) value).isEmpty()) {
                    continue;
                }
            }
            if (name.contains("toBuilder")) {
                skipLevel = true; //skip appending because its a toBuilder() method
                result = new StringBuffer(); //remove the " {" appended at L602
            }

            if (!skipLevel) {
                if (first) {
                    first = false;
                } else {
                    result.append(";");
                }
                name = name.substring(3);
                if (!name.endsWith(SDK_V2_SUFFIX_DECISION_ATTRIBUTE)) {
                    result.append("\n");
                    result.append(indentation);
                    result.append("    ");
                    result.append(name);
                    result.append(" = ");
                } else {
                    result.trimToSize();
                    result.append(indentation);
                    result.append(name, 0, name.length()
                        - SDK_V2_SUFFIX_DECISION_ATTRIBUTE.length()).append(" ");
                    skipLevel  = true; //skip end brackets of in case of Decision attribute
                    //remove SDK Decision attribute as well for decisions events
                }
                result.append(prettyPrintObject(value, methodToSkip, skipNullsAndEmptyCollections, indentation + "    ", false));
            } else {
                result.append(prettyPrintObject(value, methodToSkip, skipNullsAndEmptyCollections, indentation, false));
            }
        }

        if (!skipLevel) {
            result.append("\n");
            result.append(indentation);
            result.append("}");
        }
        return result.toString();
    }