Results 1 to 4 of 4

Thread: json controller creating .aj files with errors

  1. #1
    Join Date
    Jan 2012
    Posts
    7

    Default 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. #2
    Join Date
    Dec 2005
    Posts
    929

    Default

    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.
    Alan Stewart
    Spring Roo Committer
    twitter @alankstewart

  3. #3
    Join Date
    Jan 2012
    Posts
    7

    Default

    Quote 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

  4. #4
    Join Date
    Dec 2005
    Posts
    929

    Default

    This should be fixed now. Try the latest snapshot at http://static.springsource.org/downl...hp?project=ROO
    Alan Stewart
    Spring Roo Committer
    twitter @alankstewart

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •