Search code examples
groovymicronaut

Micronaut CompileStatic JSON object -Static type checking- No such property: bookid for class: java.lang.Object


In my Micronaut Controller I have below code to parse the JSON object. when I use @CompileStatic annotation it throwing this below error.

  @Post("/save")   
   def save(@Body Object JSON) {
    String bookid=JSON?.bookid
      String name=JSON?.name
    def b =bookService.save(bookid,name)
    return HttpResponse.created(b)
   }

Error

BookController.groovy: 58: [Static type checking] - No such property: bookid for class: java.lang.Object

Is there way to fix this error message with compilestatic annotation?

Thanks SR


Solution

  • With Help of Jeff Brown I have changed. my save method like this.

      @Post('/')
        Book save(Book b) {
            bookService.save b
        }
    

    Micronaut JSON post strip the Qutoes