Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom converter is not used for conversion in QueryMapper if value implements Iterable #819

Closed
saymeales opened this issue Mar 1, 2023 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@saymeales
Copy link

saymeales commented Mar 1, 2023

org.springframework.data:spring-data-r2dbc -> 1.5.5

I use com.fasterxml.jackson.databind.JsonNode for json values in my entities, and there is JsonNode to io.r2dbc.postgresql.codec.Json Reading/Writing converters registered in my DataAccessStrategy.

But when I want to use JsonNode as the value for update (data is instance of JsonNode), I`m get an exception:

return r2dbcTemplate.update(Entity.class)
                .matching(query(where("id").is(id).and("key").is(key)))
                .apply(Update.update("data",data)
                        .set("updated", OffsetDateTime.now()));

java.lang.IllegalArgumentException: Cannot encode parameter of type java.util.ArrayList ([[], []])
	at io.r2dbc.postgresql.codec.DefaultCodecs.encodeParameterValue(DefaultCodecs.java:276)

As I can find out, this happens because JsonNode implements Iterable and there is following code in QueryMapper#convertValue:

if (value instanceof Iterable) {
  List<Object> mapped = new ArrayList<>();
  for (Object o : (Iterable<?>) value) {
	mapped.add(convertValue(o, typeInformation.getActualType() != null ? typeInformation.getRequiredActualType()
				: ClassTypeInformation.OBJECT));
  }
  return mapped;
}

if (value.getClass().isArray()
	&& (ClassTypeInformation.OBJECT.equals(typeInformation) || typeInformation.isCollectionLike())) {
  return value;
}

return this.converter.writeValue(value, typeInformation);
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 1, 2023
@mp911de mp911de self-assigned this Mar 14, 2023
@mp911de mp911de changed the title Custom converter is not used for conversion in org.springframework.data.r2dbc.query.QueryMapper if value implements Iterable Custom converter is not used for conversion in QueryMapper if value implements Iterable Mar 15, 2023
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 15, 2023
@mp911de mp911de added this to the 1.5.10 (2021.2.10) milestone Mar 15, 2023
mp911de added a commit that referenced this issue Mar 15, 2023
We now apply converters only for Collection-like values and no longer to Iterable types.

Closes #819
@mp911de
Copy link
Member

mp911de commented Mar 15, 2023

That's fixed now.

@mp911de mp911de closed this as completed Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants