Spring Data REST: cannot sort by LocalDateTime field

Viewed 106

I am trying to sort results of a get query by using a PagingAndSortingRepository extended interface, it all works fine until I try to sort by a field which is of type LocalDateTime.

I checked the logs, when I use this field, the query just ignores sorting and there is no order by clause whatsoever.

You can find a demo on here on GitHub.

Code

Model:
@Entity
@Table(name = "simple_users")
@DynamicInsert
@DynamicUpdate
public class SimpleUser implements Serializable
{
    private static final long serialVersionUID = 1L;

    // Columns
    protected Long id;
    protected String username;
    protected LocalDateTime createdAt;
    //...

    // Constructors
    public SimpleUser() { /** Default copy constructor */ }
    //...

    // Getters
    @Id
    @Column(name = "id", updatable = false)
    @JsonProperty("id")
    public Long getId () { return this.id; }

    @Column(name = "username")
    @JsonProperty("username")
    public String getUsername () { return this.username; }

    @Column(name = "created_at")
    @JsonProperty("created_at")
    public LocalDateTime getCreatedAt () { return this.createdAt; }
    //...
}
Interface:
@RepositoryRestResource(collectionResourceRel = "simple-users", path = "simple-users")
public interface SimpleUserInterface
    extends PagingAndSortingRepository<SimpleUser, Long>
{}
URL:
http://localhost:8080/simple-users?page=0&size=10&sort=created_at,desc

Update 1:

I have changed the JsonProperty name of the field from created_at to jjaa (an arbitary name) and the problem was solved; however I changed it jj_aa (an arbitary name with an underscore in-between) and the problem has risen again. It seems that there is a problem with naming json properties with underscore and sorting.

I would very much appreciate if anyone can tell me why this happens and preferably how to solve that, because changing so many names to avoid underscores means a heavy refactoring on both back and front-end.

0 Answers
Related