Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
  • Jun 26 2017 20:07
    @remmeier banned @hibaymj
Jochen Reinhardt
this means the client sends every request twice which is a performance penalty and causes extra-load on the server.
I learned today, that using a client context with the apache http client makes the extra requests disappear.
How would I add a context to the crnk client?
Jochen Reinhardt

In io.crnk.client.http.apache.HttpClientRequest, the request is executed without HTTP-Context.

    public HttpAdapterResponse execute() throws IOException {
        listeners.stream().forEach(it -> it.onRequest(this));
        HttpClientResponse response = new HttpClientResponse(impl.execute(requestBase));
        listeners.stream().forEach(it -> it.onResponse(this, response));
        return response;

Is it a viable option to subclass HttpClientRequest and HttpClientAdapter in order to get an invocation with the same HttpContext every time?

@remmeier I made a wrapper for JpaQueryFactory that allows the default JoinType to be overridden. It works! Thanks for your help.
Good morning. I am looking to implement a custom way to return a different HTTP status code upon creating a resource based on the type of the resource. I managed to implement a custom HttpStatusBehavior which extends DefaultHttpStatusBehavior. I am trying to access the ResourceRegistry from within however even though I am implementing the ResourceRegistryAware, the ResourceRegistry is still not being set. Any ideas on how this can be achieved please?
@JochenReinhardt who is setting the necessary HTTP headers? Shouldnt they be set before making the first request?
@duncanportelli if you make use of spring boot or something similar, you can just inject it with the regular means. Otherwise a need of CrnkBoot/ModuleRegistry might be required to make sure ResourceRegistryAware is honored.
Sebastian Wyrazik
Hi! Does Crnk support sorting by @Transient Entity fields? It doesn't seem to work out-of-the-box.
For example, I'd like to sort by the sum of two normal attributes.
Mikael Blomström
Thank you @remmeier for approving crnk-project/crnk-framework#579 much appreciated!
thank you for the change! could you rebase to resolve the merge conflict?
@swyrazik what kind of support are you looking in for? in general no, as of yet, it is left to JPA.
Sebastian Wyrazik

First I'm looking for a way to use transient fields as sort parameters, meaning that Crnk would accept them in the first place. It seems that only actual fields can be used for sorting, unless I'm missing something.

Then there is the problem of translating a transient field to its corresponding JPA query. I wasn't actually expecting that that would work without some kind of customization, but I was wondering if there is some way to tell Crnk how a field is supposed to be mapped to a JPA query. For example, having the following in an Entity:

public int getTotal() {
    return a + b;

I would want to translate that into order by (o.a + o.b). Maybe Hibernate's @Formula could be used in this case.

Is there any way I could configure Crnk to allow any of the above? Any pointers on where I should look into, without having to modify the Crnk source code?


Hi there!

I'm trying to use crnk-gen to generate Java models and interfaces for my JSON:API schema.

I've followed the setup described in https://www.crnk.io/releases/stable/documentation/#_openapi, but run into a dependency problem with XML-doclet (https://github.com/MarkusBernhardt/xml-doclet). It complains about not being able to install that dependency, apparently because no repo has been defined.

I then downloaded the example app and added the plugin part in my gradle:

apply plugin: 'crnk-gen'
crnkGen {
    runtime {
        // Gradle classpath configuration to use
        configuration = 'runtime'

    // fork generation into new process to have clean environment
    forked = true

    // specify the package to look for resources
    resourcePackages = ['io.crnk.test']

    openapi {
        // enable OpenAPI generation within Gradle plugin
        enabled = true

        // specify name of openapi template in the build dir to merge onto
        templateName = "openapi-template.yml"

        // specify name of API to display in the generated OpenAPI file
        projectName = "Generated Title"

        // specify version of the API to display in the generated OpenAPI file
        projectVersion = "0.1.0"

        // specify name of openapi template in the build dir to merge onto
        projectDescription = "A generated description of the API."

        // specify location of generated sources
        genDir = file('src/resources')

However, I'm getting a Failed to apply plugin [class 'io.crnk.gen.gradle.DocletPlugin'].


  1. Does crnk-gen support my use case, i.e. passing a openapi.json scheme and let it generate interfaces and models?
  2. Has anyone ran into above mentioned error?
Ok, I think I figured out how it works and it is not intended as an OpenAPI code generator.
openapigenerator can be used to generate JSON:API documentation based off defined Crnk APIs and/or models, but can not create models and interfaces from a documentation.
Is there any example available on how to add headers to crnkClient request.
Hi, I have a use case where I am intercepting the sql before execution, modifying the query (adding a custom where clause) and then sending it on. In the process, I discovered that when I'm hitting a CRNK endpoint to fetch all records /myResource, CRNK is executing 51 queries in the process of returning my data. A lot of the queries are duplicates of each other as well. Can anyone point me to good ways to help alleviate some of that query overhead and improve performance?
Rehab Reda
Hi,how can I represent true/false in the nested filters
If I want to sayd FilerSpec.and(certainConditions)
and this certain conditions want to add true or false to one of the conditions without having a field name
@kushal69 yes, there is HttpAdapter with various implementations like for appache and okhttp. You may use that or directly the underlying implementation to add custom logic.
@rehab-reda0 what exactly are you looking for? can you make an example?
@uhpotter why are there that many queries? are there many inclusions? is it a default JPA repository? without inclusion there are typically one or two queries (data and maybe total count). In case you make use of the Jpa repository, you are free to build on top of that implementation, or even better, add a Repository decorator in front of it to do caching. But generally make sure you are not suffering from N+1 issues somewhere.
@swyrazik sorry, a late reply. you can always intercept and add custom logic to map the transient field to actual JPA fields (also with a decorator or custom implementation of the repository). But for the sake of simplicity I usually try to avoid this things when it comes to JPA. In many cases a DB View may suffice to let the DB take care of those things.

Hi everbody,
I am new in JsonApi and I see this great library crnk.

My question is where to put custom logic written in services.
In standard Spring Boot Rest Api we have controllers -> services -> repositories
but in JsonApi (crnk) we have resources and repositories.
Resources is controllers in standard Rest Api ?
Where I can put custom logic and how.

Custom logic is all in the repositories. The "lower-level plumbing" is being taken care of by JSON:API as standard and crnk as implementation. That should be fine for 98% of the use cases, and there are hooks for the other 2%.
3 replies
Hi @remmeier can I have a JSONObject (i.e org.json.JSONObject) as attribute type?
Currently I can only use this if the API caller passes the attribute as string and then jackson will parse the json object from string. Is there any other option? Thanks!
2 replies
Is there any way to generate swagger documentation for Spring boot maven project which is using crnk library
2 replies
@remmeier thank you for the the reply. One more question - I am using crnk-gen-openapi lib to generate open api document in that i need to add headers (like Authorization) which we will be consuming at crnk. Can you please suggest on this ?
1 reply
Lasse Immonen

hello! wanting to ask about a PR and possible new releases coming out. the PR is this one: crnk-project/crnk-framework#793. how does it look, is it okay?

how about plans for a new release? anything projected at the moment?


Hello there, I'm trying to make use of the @JsonApiMetaInformation, I followed the documentation but I don't see it in my response when I try it with the postman, here is the code of my resource:

 * The persistent class for the EF_V_API_TW_RUECKLIEF_KOPF_DET database table.
@JsonApiResource(type = "return", resourcePath = "returns")
public class Return implements Serializable {
  private static final long serialVersionUID = 1L;


  private ReturnMeta meta;

  public static class ReturnMeta implements MetaInformation, Serializable {

    private static final long serialVersionUID = 8129518187692599777L;

    private Boolean patchable = true;

    public Boolean getPatchable() {
      return patchable;

    public void setPatchable(Boolean patchable) {
      this.patchable = patchable;


Am I missing something in the repository?
Thank you very much.

looks good to me. Meta data not visible at all? ResourceMapper would be the class responsible for writing meta data and other fields. So if there is an issue, it should be visible in there.

Hi @remmeier .
How works crnk-security ?
I put
config.permitRole("USER", ResourcePermission.ALL);

but on every request It gives me 401 unauthorized.
In spring-security I have 2 roles ROLE_USER, ROLE_ADMIN.

In spring security @PreAuthorize("hasRole('USER')") this works.

looks good to me. The DEBUG log should help track it down if there is an issue. On startup there (probably) is also a message what kind of SecurityProvider is installed, should be a spring or servlet one I think in the spring boot case.
@remmeier Was wondering if you could point me in the right direction..
I have a use case where I need to generate JSONAPI output, but not via a REST API. What is the best entry point/service that I can use to take advantage of the Resources / Repos that I already have in place ?
Is it expected that unknown fields are ignored within nested attributes?
Let's say our server (using crnk) accepts requests with attributes {name: {first: "Max", last: "Powers"}}, we would receive a HTTP400 when sending additional, unknown attributes on the same level as "name". But it is ignored inside the nested object:
{name: {first: "Max", last: "Powers"}, test: 1} -> BAD_REQUEST
{name: {first: "Max", last: "Powers", test: 1}} -> CREATED (but "test" is of course ignored and not persisted)
We modeled these nested objects as additional POJOs that are used by our main JsonApiResource
@whgibbo maybe have a look at the CrnkServlet and JsonApiRequestProcessor. Something in that area should help
2 replies
@fchill @JsonApiEmbeddable could work (it is fairly recent and may miss something), generally it will allow to track that nested attribute, rather then just relying on Jackson.
Is there any reasoning behind nested resources? How deep can they be nested and is there an estimation when it is no longer experimental?
Is Crnk support spring Autowired dependency injection?
I tried to inject bean using the following code. But no luck. @Component
public class ExampleRepository extends ResourceRepositoryBase<Example, String> {
private ApplicationContext appContext;
public ExampleRepository() {
public class AppLoader {
CSVLoader getCSVData() {
return new CSVLoader();
public class CSVLoader {
public static List<String> equipmentData=new ArrayList<>();
CSVLoader() {
Jochen Reinhardt
I'm using crnk with DTO mapping and many-to-many relationships
When I define a many-to-many relationship in the entity and directly expose the entity as crnk resource, the relationship works as expected.
When I expose the same data with a DTO mapper enabled, the relationship does not work anymore.
I found, that in GetFromOwnerStrategy for the entity, the source actually is the JPA entity and the fieldAccessor call triggers JPA lazy loading.
Whereas when DTO mapping is in place, the source is the DTO and the fieldAccessor returns null
Is this a bug?
Hi Team! What's the best way to pass the database info in the response headers? My initial thought is to use a response filter and call database for required info. But I don't like having database dependency from a filter class. Is there a way to pass the database info into response headers from the repository class itself?

Hi all,

i am trying to do a filter to check if a date value exists within a certain 2 ranges and using the below filter:


I believe it is correct but crnk is only taking into consideration the last AND. Is this an issue?