class JsonGenerator {

    public static JsonValue createJsonObject(Object object) throws JsonException {
        if (object == null) {
            return new NullValue();
        }
        Class<?> aClass = object.getClass();
        JsonValue jsonRootValue = new ObjectValue();
        JsonMethod[] getters;
        try {
            getters = methodsCache.get(aClass);
        } catch (ExecutionException e) {
            propagateIfPossible(e.getCause());
            throw new JsonException(e.getCause());
        }
        for (JsonMethod getter : getters) {
            try {
                Object getterResult = getter.method.invoke(object);
                Types getterResultType = JsonUtils.getType(getterResult);
                if (getterResultType == null) {
                    jsonRootValue.addElement(getter.field, createJsonObject(getterResult));
                } else {
                    jsonRootValue.addElement(getter.field, createJsonValue(getterResult, getterResultType));
                }
            } catch (InvocationTargetException | IllegalAccessException e) {
                throw new JsonException(e.getMessage(), e);
            }
        }
        return jsonRootValue;
    }

}