Skip to content

Feature: ValueBuilder#convert support Map #115

Open
@honhimW

Description

@honhimW

Is your feature request related to a problem?

Sometimes we need to allow the field names to be configured during runtime.

Describe the solution

A simple and flexible approach is to support using Map as the content input, which not only solves the problem but also avoids the use of reflection.

Alternative methods

Basically as follows:

private static <T> ValueMut convertObject(final T object) {
  ...
  // if object instanceof Map<?, ?>
  final List<EntryMut> entries = new ArrayList<>(map.size());
  for (Map.Entry<?, ?> entry : map.entrySet()) {
    Object key = entry.getKey();
    Object value = entry.getValue();
    final String name = key.toString();
    final ValueMut valueMut = convert(field.get(object));
    if (valueMut != null) {
      entries.add(EntryMut.newEntry(name, valueMut ));
    }
  }
}

SurrealDB version

any

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions