Prasanth A R
Prasanth A R

Reputation: 4174

How to Convert List to Json array in scala

This is my code and here the return type is list but the list convert to array and the return type change to string

    @RequestMapping(value =Array( "/StandardChange.html"))
    @ResponseBody
    def  findDivisionOfStandards(@RequestParam  divisionid:Long):List[Division] ={

     var division:List[Division]= null
     if (divisionid != null) {

        division  = divisionService.findDivisionByStandardId(divisionid)            
    }       
     division  
    }

I tried this but this is not working

the Return type change List to String and the value change to List to Json Array

  @RequestMapping(value =Array( "/StandardChange.html"))
  @ResponseBody
    def  findDivisionOfStandards(@RequestParam  divisionid:Long):String ={

      var division:List[Division]= null

      if (divisionid != null) {

           division  = divisionService.findDivisionByStandardId(divisionid)         

        }   
       var divisionjsonArray=  division.toArray     **json convert should be here**

      divisionjsonArray
    }

Upvotes: 0

Views: 1651

Answers (1)

daaatz
daaatz

Reputation: 394

compact(render(decompose(division)))

Upvotes: 2

Related Questions