Hi,
I'm using Spring Boot to return some results from a HAPI FHIR backend. I'm getting an infinite recursion error when trying to return a Bundle from a generic rest client. Here's the code snippet:
@GetMapping(value = {"/condition/", "/condition"})
public Bundle getAll() {
Bundle bundle = clinacuityProperties.getFhirContext().newRestfulGenericClient(url)
.search()
.forResource(Condition.class)
.returnBundle(Bundle.class)
.execute();
return bundle;
}
Here's the error that I'm running into:
org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: org.hl7.fhir.dstu3.model.StringType["idElement"]->org.hl7.fhir.dstu3.model.StringType["idElement"]->org.hl7.fhir.dstu3.model.StringType["idElement"]-> [. . . repeats several hundred times . . .] ->org.hl7.fhir.dstu3.model.StringType["idElement"]->org.hl7.fhir.dstu3.model.StringType["formatCommentsPre"])
(There's a full stack trace attached)
I don't know what could possibly be wrong with this, and I've tried adding each entry to a List<Condition> and returning that instead, but it still crashes. It works fine if I go to the same {url}/Condition and get all the conditions (they're returned normally), but the client is failing with that weird error. Do I need to use some parser or add some setting to exclude recursive results? The Conditions on my test server are very simple objects with minimal data in them.
Thanks!
- JK Accetta