Skip to content

NoClassDefFoundError when sort query is applied #163

@lewis-munene

Description

@lewis-munene

I am getting the following error when I add a sort query:
java.lang.NoClassDefFoundError: Could not initialize class io.github.perplexhub.rsql.jsonb.JsonbSupport. If I remove the sort query, the filter works.

Environment:

Spring Boot: 3.3.4
Java: 21

Dependencies:

 dependencoes {
        implementation("io.github.perplexhub:rsql-jpa-spring-boot-starter:6.0.23")
 }

My Model:

@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Table(name = "event")
public class Event {
    ...
    @Column(nullable = false, unique = true, length = 50)
    private String code;
    ...
}

The code:

    public Response<List<Event>> queryEvent(String filter, String sort, Integer first, Integer after) {
        Specification<Event> specification = toSpecification(filter, sort);

        Page<Event> eventPage = eventRepository.findAll(specification, toPageable(first, after));

        return Response.<List<Event>>builder()
                .data(eventPage .getContent())
                .pageInfo(PageInfo.builder()
                        .hasNextPage(eventPage .hasNext())
                        .hasPreviousPage(eventPage .hasPrevious())
                        .startCursor(eventPage .getNumberOfElements() > 0
                                ? eventPage .getContent().getFirst().getId()
                                : null)
                        .endCursor(eventPage .getNumberOfElements() > 0
                                ? eventPage .getContent().getLast().getId()
                                : null)
                        .totalRecords(eventPage.getTotalElements())
                        .build())
                .build();
    }


   public static <T> Specification<T> toSpecification(String rsqlQuery, String sortRsql) {
        Specification<T> specification;

        if (StringUtils.hasText(rsqlQuery)) {
            specification = RSQLJPASupport.toSpecification(rsqlQuery);

            if (StringUtils.hasText(sortRsql)) {
                specification = specification.and(RSQLJPASupport.toSort(sortRsql));
            }
        } else if (StringUtils.hasText(sortRsql)) {
            specification = RSQLJPASupport.toSort(sortRsql);
        } else {
            specification = null;
        }
        return specification;
    }

    public static Pageable toPageable(Integer first, Integer after) {
        // Default to page 0 for page and 50 for pageSize in case the inputs have problems
        return PageRequest.of(
                after == null ? 0 : after,
                first == null ? 50 : first
        );
    }

This is the way I am calling the query method: queryEvent("", "version,asc", null, null);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions