com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError)

Hey all!

I have created a module trying out some customised get api like below

public ResponseEntity< List<Patient> > search(@RequestParam(value = "mobile", required = false) String mobile) throws ResponseException {
    List<Patient> results = null;
    if (StringUtils.isNotBlank(mobile)) {
        if(!StringUtils.isNumericSpace(mobile)) {
            return new ResponseEntity<>(new ArrayList<>(), HttpStatus.NO_CONTENT);

        }else if( validateNumber(mobile)) {

            results = Context.getPatientService().getAllPatients()
                    .filter(person -> sameMobile(person.getAttributes(), mobile))

            List<Patient> allPatients = Context.getPatientService().getAllPatients();
            for(Patient patiient: allPatients){
                if(sameMobile(patiient.getPerson().getAttributes(), mobile)) {
        Boolean resultsExist = results != null && !results.isEmpty();
        if (!resultsExist) {
            return new ResponseEntity<>(new ArrayList<>(), HttpStatus.NO_CONTENT);
        return new ResponseEntity<>(results, HttpStatus.OK);
    return new ResponseEntity<>(new ArrayList<>(), HttpStatus.NO_CONTENT);

on executing my api with postman /mymodule/patient?mobile=0708443737, i get an Infinite recursion (StackOverflowError) but if i add this functionality as a search handler in, it works pretty well.

I am running openmrs instance using the sdk, Reference Application 2.12.2.

@ibacher @dkayiwa what might i be missing here

The link you shared for your error log does not seem to work.

@dkayiwa, i dont know what my earlier link was invalidated, am sorry for that. i have created another on

ohhhh its broken i guess i have exceeded the characters limit

@dkayiwa pastebin is invalidating my log each time i create a new paste so am going to upload it here log.txt (418.4 KB)

Are you trying to duplicate the already existing patient end point?

I first created the class in openmrs-module-web until it worked. I migrated the logic in my new module and deleted the handler I had created

But the patient end point is already implemented. So my point is, why migrate it to your custom module?

i wanted to introduce in another simple functionality of searching by mobile and i thought of keeping the name would give a better hint of the results of the endpoint.

Did you follow these guidelines? Adding a Web Service Step by Step Guide for Module Developers - Documentation - OpenMRS Wiki

Yes I am using openmrs web services rest version 2.36.0

Can you point me to your custom resource class? Just like these ones: at master · openmrs/ · GitHub

1 Like

i didn’t create any resource, for now. So my Module only has one controller · GitHub and 2 classes responsible for the module’s activation

You need a resource to handle your end point’s domain object.

1 Like

hey @dkayiwa creating a corresponding handler resource didn’t work for me, unless there are more tweaks to do with the resource.

Which OpenMRS platform versions does your resource support?

i am using openmrs version 2.5.0 in my module. I am running my module against Reference application 2.12 which runs core version 2.4.3

Take a second look at your resource, and you will understand what am asking for.

@dkayiwa i have changed supportedOpenmrsVersions = { "1.8.*" } to supportedOpenmrsVersions = { "1.*", "2.*" } but the error has persisted

Commit your entire module on github. And also share the exact full url that you are accessing for this end point, to get the error.