How AI is applied across API Evangelist and APIs.io. Read my AI disclosure →
API Evangelist API Evangelist
Discovery
Learnings
Guidance
Toolbox
Alignment
API Evangelist LLC

Is it a bad practice to use many instanceof checks in a Spring Boot REST controller to map multiple persistence models?

calendar_today May 27, 2026 person LESTER PAYES domain spring-boot

I am building a Spring Boot REST API for a tree structure. The project uses an OpenAPI contract-first approach, so my controller implements a generated interface: java @RestController public class TreeController implements TreeApi{ The API must support multiple storage implementations selected by configuration: app.storage=memory app.storage=postgres app.storage=mongo The response models come from OpenAPI, for example: NodeResponse TreeNodeResponse NodeListResponse NumberResponse ValidationResponse The problem is that each storage implementation returns a different internal model: CustomTreeNo

open_in_new Read original post