Uploaded image for project: 'Spring Roo'
  1. Spring Roo
  2. ROO-2341

Web view and JSON view inconsistent. JSON view should use deepSerialize() or allow option to

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 1.1.3.RELEASE
    • Fix Version/s: 1.1.4.RELEASE
    • Component/s: WEB MVC
    • Labels:
      None

      Description

      json all creates json views for all the roo controllers

      example:

      @RequestMapping(value = "/

      {id}", method = RequestMethod.GET, headers = "Accept=application/json")
      @ResponseBody
      public Object UserController.showJson(@PathVariable("id") Long id) {
      User user = User.findUser(id);
      if (user == null) { HttpHeaders headers= new HttpHeaders(); headers.add("Content-Type", "application/text"); return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND); }
      return user.toJson();
      }

      However, this view is inconsistent with the normal GET:

      @RequestMapping(value = "/{id}

      ", method = RequestMethod.GET)
      public String UserController.show(@PathVariable("id") Long id, Model uiModel)

      { uiModel.addAttribute("user", User.findUser(id)); uiModel.addAttribute("itemId", id); return "users/show"; }

      as the normal GET is deep (aka, you can see all the users @OneToMany properties such as Authorities, etc.)

      This is because the generated JSON code in the underlying object:

      @RooJavaBean
      @RooToString
      @RooEntity
      @RooSerializable
      @RooJson
      public class User {

      @NotNull
      private String name;
      }

      generates:
      public String User.toJson()

      { return new JSONSerializer().exclude("*.class").serialize(this); }

      to be consistent with the normal GET view, it should generate this:
      public String User.toJson()

      { return new JSONSerializer().exclude("*.class").deepSerialize(this); }

      Otherwise, ROO should provide a mechanism for doing this:

      @RooJson(deep=true)

      However, to be consistent, you might want to consider deep being the default. Otherwise, the same data is not being delivered as the default GET view.

        Attachments

          Activity

            People

            Assignee:
            sschmidt Stefan Schmidt
            Reporter:
            sdmurphy Scott Murphy
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: