Check out these two controller methods. They both use the same object. The first one, called backtestStrategy correctly returns a JSON formatted response. The second one, called getAllStrategies, returns an array of values not in JSON format. All the values are there but none of the keys.
@RestController
@RequestMapping("/api/v1")
public class StrategyController {
@Autowired
private StrategyService strategyService;
@GetMapping("/backtest")
public Response backtestStrategy(@RequestParam String strategyName, @RequestParam String symbol) {
Response response = strategyService.backtestStrategy(strategyName,symbol);
return response;
}
@GetMapping("/strategies")
public List<Response> getAllStrategies() {
List<Response> strategies = strategyService.getAllStrategies();
return strategies;
}
}
Suggestions?
EDIT: The first one apparently works because I create the Response object, populate it, save it to a db, and return the created object. The second one is reading from the db. The values are in the db correctly.
Here is the order of operations: controller calls service implementation which is defined by an interface. Service implementation calls repository, which makes the db query. Here is the query:
@Query(value="select * from strategy", nativeQuery = true)
List<Response> getAllStrategies();
Responseclass.