public static Map<String, Object> asMap(Object object) {
        // YAML can have numbers as keys
        Map<String, Object> result = new LinkedHashMap<>();
        if (!(object instanceof Map)) {
            // A document can be a text literal
            result.put("document", object);
            return result;
        }

        Map<Object, Object> map = (Map<Object, Object>) object;
        for (Map.Entry<Object, Object> entry : map.entrySet()) {
            Object value = entry.getValue();
            if (value instanceof Map) {
                value = asMap(value);
            }
            Object key = entry.getKey();
            if (key instanceof CharSequence) {
                result.put(key.toString(), value);
            } else {
                // It has to be a map key in this case
                result.put("[" + key.toString() + "]", value);
            }
        }
        return result;
    }
@Test
    public void testAsMap() {
        Map<String, Object> map = MapUtil.asMap("abc");
        Assertions.assertEquals(Collections.singletonMap("document", "abc"), map);

        Map<Object, Object> source = new HashMap<>();
        source.put("map", Collections.singletonMap("key", "abc"));
        source.put("list", Collections.singletonList(123));
        source.put(123, 123);

        Map<String, Object> result = new LinkedHashMap<>();
        result.put("list", Collections.singletonList(123));
        result.put("map", Collections.singletonMap("key", "abc"));
        result.put("[123]", 123);

        map = MapUtil.asMap((Object) source);
        Assertions.assertEquals(result, map);
    }