eclipse-vertx / eclipse-vertx/vertx-codegen

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

Open
#312 5 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
111
Forks
89
PR merge metrics
No merged PRs in 30d

Description

### 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.