@Override
    public KvMetadata resolveMetadata(
            boolean isKey,
            List<MappingField> resolvedFields,
            Map<String, String> options,
            InternalSerializationService serializationService
    ) {
        Map<QueryPath, MappingField> fieldsByPath = extractFields(resolvedFields, isKey);

        Entry<QueryDataType, Class<?>> entry = getTopLevelType(fieldsByPath)
                .<Entry<QueryDataType, Class<?>>>map(type -> entry(type, loadClass(type.getObjectTypeMetadata())))
                .orElseGet(() -> {
                    Class<?> typeClass = loadClass(options, isKey);
                    return entry(QueryDataTypeUtils.resolveTypeForClass(typeClass), typeClass);
                });
        QueryDataType type = entry.getKey();
        Class<?> typeClass = entry.getValue();

        if (type.getTypeFamily() != QueryDataTypeFamily.OBJECT || type.isCustomType()) {
            return resolvePrimitiveMetadata(isKey, resolvedFields, fieldsByPath, type);
        } else {
            return resolveObjectMetadata(isKey, resolvedFields, fieldsByPath, typeClass);
        }
    }
@Test
    @Parameters({
            "true",
            "false"
    })
    public void when_noKeyOrThisPrefixInExternalName_then_usesValue(boolean key) {
        Map<String, String> options = Map.of(
                (key ? OPTION_KEY_FORMAT : OPTION_VALUE_FORMAT), JAVA_FORMAT,
                (key ? OPTION_KEY_CLASS : OPTION_VALUE_CLASS), Object.class.getName()
        );

        KvMetadata metadata = INSTANCE.resolveMetadata(
                key,
                singletonList(field("field", QueryDataType.INT, "extField")),
                options,
                null
        );
        assertThat(metadata.getFields()).containsExactly(
                key
                        ? new MapTableField[]{
                        new MapTableField("__key", QueryDataType.OBJECT, true, QueryPath.KEY_PATH)
                }
                        : new MapTableField[]{
                        new MapTableField("field", QueryDataType.INT, false, new QueryPath("extField", false)),
                        new MapTableField("this", QueryDataType.OBJECT, true, QueryPath.VALUE_PATH)
                });
    }