Json-API : format custom Rest endPoint in SpringBoot

560 views Asked by At

Don't hesitate to tell me if I am not going in the right direction.

In my project, we provide several endpoints for custom objects that contain part of different entities. I would like these endpoints response and request parameter if any, to respect the JSON-API. The use of these ViewObjects give us the ability to send only data specifically used by the client and not all the content of the object with complex children.

I am using SpringBoot and I have tried to follow the Katharsis documentation for the implementation.

MyApplication.java

@Configuration
@SpringBootApplication
@Import({KatharsisConfigV3.class})
public class MyApplication {
    //default Spring boot main
}

MyObjectController.java

@RequestMapping(value = "/api/myobjects", method = RequestMethod.GET)
public List<MyObjectVO> getMyObjects() {
    // Get and return complex objects after several tests on data
}

MyObjectVO.java

@JsonApiResource(type = "myObject")
public class MyObjectVO{
    @JsonApiId
    private String id;
    private String name;
    // etc...
}

application.properties

katharsis.pathPrefix=/api
katharsis.resourcePackage=com.me

Currently the output is

[ { "id": "1", "name": "MyObject" }, { "id": "2", "name": "MyObject2" } ]

Is it possible and how to use Katharsis to do the mapping as Jackson is currently doing but in the JSON-API format, without modifying all the current architecture of the project.

Thanks for your help and advice

0

There are 0 answers