Announcement Announcement Module
No announcement yet.
1.1.0M3 json support does not seem to work for finders Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 1.1.0M3 json support does not seem to work for finders

    Hi, first let me congratulate you all on what is an impressive developer tool

    I'm using the 1.1.0M3 version of Spring Roo.

    I added some finders to my application (both standard finders using the 'finder add' command and more complex finders adding directly to my Entity and Controller). I also added json support to my objects using the 'json add' command.

    My finders work fine in the UI but not in json. But the standard 'list all blah blah' pages can be retrieved in json. The type of commands I'm using to retrieve in json are...

    works (retrieves all venues):
    curl -H 'Accept:application/json' -X GET http://localhost:8080/venues/list

    does not work (calls a finder):
    curl -H 'Accept:application/json' -X GET http://localhost:8080/venues?find=ByNameLike&name=La

    Do I need to configure something else at the finder level for the 1.1.0M3 json to be supported for these? Any help anyone can provide would be greatly appreciated. I've been scratching my head with the whole json support for the past week. I had originally had the ContentNegotiatingViewResolver configured for json and had successfully removed circular dependencies using the @jsonignoreproperties annotation but were still seeing problems where the json result for one entity was returning along with it the full list of another type of entity rather than just the specific instances of entities that were related to it via a foreign key, so ditched that to try the new 1.1.0M3 inbuilt json support.

  • #2

    ok, so I spotted where it was going wrong and have a work around.

    Say my entity and controller were created as Venue and VenueController. Looking in the generated VenueController_Roo_Controller.aj I could see that there was a list() mehod and a matching listJson() method. But looking at the finder there was the findBy() type of method but no corresponding findByJson(() method.

    To get around this I added the relevant findByJson() method directly to my controller.

    So, for example, my VenueController_Roo_Controller.aj contained the following generated finder method:

        @RequestMapping(params = "find=ByNameLike", method = RequestMethod.GET)
        public String VenueController.findVenuesByNameLike(@RequestParam("name") String name, Model model) {
            model.addAttribute("venues", Venue.findVenuesByNameLike(name).getResultList());
            return "venues/list";
    To make the above json aware I added the following method directly to my VenueController:
        @RequestMapping(headers = "Accept=application/json", params = "find=ByNameLike", method = RequestMethod.GET)
        public String findVenuesByNameLikeJson(@RequestParam("name") String name) {
    		Collection<Venue> venues = (Collection<Venue>) Venue.findVenuesByNameLike(name).getResultList();  	
            return Venue.toJsonArray(venues);


    • #3
      Using Path instead of params

      As soon as I upgraded a project I had to 1.1.0 this was my first question ... Where is the finder json methods? It seems you can integrate the previous treatment of using the ContentNegotiatingViewResolver (ie .json). Perhaps thats still the preferred method?

      I liked your idea except IMHO its nicer with paths. It was also easier to test. I was playing with the clinic sample and created this:

          @RequestMapping(value= "/find/ByOwner/{owner}", method = RequestMethod.GET, headers = "Accept=application/json")
          public String PetController.findPetsByOwnerJson(@PathVariable("owner") Owner owner) {
              return Pet.toJsonArray(Pet.findPetsByOwner(owner).getResultList());
      If your just trying it out, I found it easier to stick in the PetController_Roo_Controller.aj file, otherwise you need to get the appropriate imports on the main

      After launching the app and using the web ui to add some owners and pets, something like this should get you json results:

      curl -v -H 'Accept: application/json' -X GET http://localhost:8080/petclinic/pets/find/ByOwner/1