micronaut-projects / micronaut-data

Ahead of Time Data Repositories
Apache License 2.0
465 stars 197 forks source link

Cannot unmarshal jsonb into an embedded list. #1064

Closed l-wegner closed 3 years ago

l-wegner commented 3 years ago

Thanks for reporting an issue, please review the task list below before submitting the issue. Your issue report will be closed if the issue is incomplete and the below tasks not completed.

NOTE: If you are unsure about something and the issue is more of a question a better place to ask questions is on Stack Overflow (https://stackoverflow.com/tags/micronaut) or Gitter (https://gitter.im/micronautfw/). DO NOT use the issue tracker to ask questions.

Task List

Steps to Reproduce

  1. maven package
  2. run the test suite.

Expected Behaviour

Both tests pass.

Actual Behaviour

The test unmarshalling the entity from the database fails, because jackson does not know, which type is in the list.

Serialization is handled by the jsonCodec, which delegates eventually to jackson AbstractSqlRepositoryOperations#setStatementParameter. Deserialization via jsonCodec is not applied and the readProperty returns a plain string ( SqlResultEntityTypeMapper#readEntity).

Environment Information

Example Application

l-wegner commented 3 years ago

I managed to work around that by introducing a POJO GistListEntries instead of List and registering type converters for it at micronaut.

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Introspected
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
public class GistListEntries {
    @Singular
    @Valid
    @NotNull
    @ValidAttributeGroup
    List<GistListEntry> members;
}
dstepanov commented 3 years ago

You should remove @JsonTypeInfo(use= JsonTypeInfo.Id.CLASS) from the GistListEntry then it works with the latest version