public static ReferenceMap toReferenceMap(Map<String, Object> m) {
        final ImmutableMap.Builder<String, Reference> mapBuilder = ImmutableMap.builder();
        for (Map.Entry<String, Object> entry : m.entrySet()) {
            final Object value = entry.getValue();
            if (value instanceof Collection) {
                @SuppressWarnings("unchecked") final List<Object> childList = (List<Object>) value;
                mapBuilder.put(entry.getKey(), toReferenceList(childList));
            }
            if (value instanceof Map) {
                @SuppressWarnings("unchecked") final Map<String, Object> childMap = (Map<String, Object>) value;
                mapBuilder.put(entry.getKey(), toReferenceMap(childMap));
            } else {
                final ValueReference valueReference = ValueReference.of(value);
                if (valueReference != null) {
                    mapBuilder.put(entry.getKey(), valueReference);
                }
            }
        }
        return new ReferenceMap(mapBuilder.build());
    }
@Test
    public void toReferenceMap() {
        final ImmutableMap<String, Object> map = ImmutableMap.<String, Object>builder()
                .put("boolean", true)
                .put("double", 2.0D)
                .put("float", 1.0f)
                .put("integer", 42)
                .put("long", 10000000000L)
                .put("string", "String")
                .put("enum", TestEnum.A)
                .put("list", ImmutableList.of(1, 2.0f, "3", true))
                .put("nestedList", ImmutableList.of(
                        ImmutableMap.of( "k1", "v1", "k2", 2),
                        ImmutableMap.of( "k1", "v2", "k2", 4)
                ))
                .put("map", ImmutableMap.of(
                        "k1", "v1",
                        "k2", 2))
                .build();
        final ReferenceMap expectedMap = new ReferenceMap(ImmutableMap.<String, Reference>builder()
                .put("boolean", ValueReference.of(true))
                .put("double", ValueReference.of(2.0D))
                .put("float", ValueReference.of(1.0f))
                .put("integer", ValueReference.of(42))
                .put("long", ValueReference.of(10000000000L))
                .put("string", ValueReference.of("String"))
                .put("enum", ValueReference.of(TestEnum.A))
                .put("list", new ReferenceList(ImmutableList.of(
                        ValueReference.of(1),
                        ValueReference.of(2.0f),
                        ValueReference.of("3"),
                        ValueReference.of(true))))
                .put("nestedList", new ReferenceList(ImmutableList.of(
                        new ReferenceMap(ImmutableMap.of(
                        "k1", ValueReference.of("v1"),
                        "k2", ValueReference.of(2))),
                        new ReferenceMap(ImmutableMap.of(
                                "k1", ValueReference.of("v2"),
                                "k2", ValueReference.of(4))))))
                .put("map", new ReferenceMap(ImmutableMap.of(
                        "k1", ValueReference.of("v1"),
                        "k2", ValueReference.of(2))))
                .build());

        final ReferenceMap valueReferenceMap = ReferenceMapUtils.toReferenceMap(map);
        assertThat(valueReferenceMap).isEqualTo(expectedMap);
    }