Announcement Announcement Module
Collapse
No announcement yet.
json controller creating .aj files with errors Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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?

  • #2
    It could be a bug - raise an issue and attach a script to reproduce the problem. Also attach a backup of your project using the Roo backup command. Fields annotated with @Id in the .java class take precedence over generated default identifiers in the jpa entity ITD, however, there could be an issue with the json ITD.

    Comment


    • #3
      Originally posted by Alan Stewart View Post
      It could be a bug - raise an issue and attach a script to reproduce the problem. Also attach a backup of your project using the Roo backup command. Fields annotated with @Id in the .java class take precedence over generated default identifiers in the jpa entity ITD, however, there could be an issue with the json ITD.
      Added: https://jira.springsource.org/browse/ROO-3040

      Comment


      • #4
        This should be fixed now. Try the latest snapshot at http://static.springsource.org/downl...hp?project=ROO

        Comment

        Working...
        X