Search code examples
spring-data-jpaprojectionspring-data-rest

Issue with projection in SpringDataRest and @Lob attribute


I have an Entity Person :

@Entity
public class Person implements Serializable {
@Id
@GeneratedValue(strategy = AUTO, generator = "PERSON_SEQ")
private Integer idPerson;
private String lastName;
private String firstName;
@Lob
private byte[] picture;

A repository

public interface PersonRepository extends PagingAndSortingRepository<Person, Integer> {}

A projection

@Projection(name = "picture", types = { Person.class })
public interface ProjectionPicturePerson {
  byte[] getPicture();

}

When i used the projection : ..../persons/1?projection=picture i have this error

There was an unexpected error (type=Internal Server Error, status=500). Could not write content: [B cannot be cast to [Ljava.lang.Object; (through reference chain: org.springframework.data.rest.webmvc.json.["content"]->$Proxy109["picture"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: [B cannot be cast to [Ljava.lang.Object; (through reference chain: org.springframework.data.rest.webmvc.json.["content"]->$Proxy109["picture"])

When i use a projection on a String, exemple lastName it works

@Projection(name = "lastName", types = { Person.class })
public interface ProjectionLastName {
   String getLastName();
}

When i don't use projection it works too

jackson serialize the image attribute

Is there a restriction on Blob ?


Solution

  • That's a bug in ProxyProjectionFactory. I've filed and fixed DATACMNS-722 for you scheduled to be in the upcoming services releases (mid next week).