@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, __key",
            "false, this"
    })
    public void test_resolvePrimitiveMetadata(boolean key, String path) {
        Map<String, String> options = Map.of(
                (key ? OPTION_KEY_FORMAT : OPTION_VALUE_FORMAT), JAVA_FORMAT,
                (key ? OPTION_KEY_CLASS : OPTION_VALUE_CLASS), int.class.getName()
        );

        KvMetadata metadata = INSTANCE.resolveMetadata(
                key,
                singletonList(field(path, QueryDataType.INT, path)),
                options,
                null
        );

        assertThat(metadata.getFields()).containsExactly(
                new MapTableField(path, QueryDataType.INT, false, QueryPath.create(path))
        );
        assertThat(metadata.getQueryTargetDescriptor()).isEqualTo(GenericQueryTargetDescriptor.DEFAULT);
        assertThat(metadata.getUpsertTargetDescriptor()).isEqualTo(PrimitiveUpsertTargetDescriptor.INSTANCE);
    }