json controller creating .aj files with errors
I have an entity (mapped to a db) in which the @Id field is not called "id". I can't change the db. I have the @Id annotation on the proper field/column value. This works fine, but when I create the controller, the controller_json.aj file is created with errors. Code snippets below:
Entity:
-------
Code:
@RooJson
@RooJpaActiveRecord(table=xxx)
public class Product {
@Id
private String productName;
(other fields)...
}
Controller:
------------
Code:
@RooWebJson(jsonObject = Product.class)
@Controller
@RequestMapping("/products")
public class ProductController {
}
ProductController_Roo_Controller_Json.aj
----------------------------------------------
Code:
@RequestMapping(value = "/{productName}", headers = "Accept=application/json")
@ResponseBody
public ResponseEntity<String> ProductController.showJson(@PathVariable("productName") String productName) {
Product product = Product.findProduct(id); // why is this id?
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
if (product == null) {
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
return new ResponseEntity<String>(product.toJson(), headers, HttpStatus.OK);
}
As you see above, it names the variable that's passed into the method accurately, but then the call it makes on the Entity still references the "id" field as id.
Is this a bug or am I not using the JSON functionality correctly?