Skip to content

@DataObject does not handle json in String format when generating Converters #312

@pendula95

Description

@pendula95

Version

3.9.2

Context

When @'DataObject' is generated with its fromJson method objects that are import io.vertx.core.json.JsonObject only accept JsonObject as valid option for mapping. Example generated constructor:

private JsonObject attributes;

For this property following code is generated:

case "attributes":
          if (member.getValue() instanceof JsonObject) {
            obj.setAttributes(((JsonObject)member.getValue()).copy());
          }
          break;

Generated code should be like:

case "attributes":
          if (member.getValue() instanceof JsonObject) {
            obj.setAttributes(((JsonObject)member.getValue()).copy());
          } else if (member.getValue() instanceof String) {
            obj.setAttributes(new JsonObject(member.getValue()));
          }
          break;

If for example from DB I get a String field that has JSON formating this property will never get mapped. On the other hand if this POJO is generated by Jackson function this field with get mapped.
SomeDTO someDTO = json.mapTo(SomeDTO.class);

Extra

Is this something that was intended or just wasn't considered. In my eyes this is a standard approach as vertx json wrapper accepts String as valid for when generating Json objects. I can submit a PR if we agree to go with this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions