简体   繁体   中英

How can I retrieve the body as JSON Play framework 1.5

I`m using Play Framework 1.5 and I'm new in this framework. How can I retrieve the body as JSON when i sent a request body with JSON:

{
  "inputNo": 111111,
  "name": "検証 太郎"
}

AFAIK there is no built in JSON binding support in Play1x. You can implement binding process manually by using @Before annotation in controller class. In the @Before annotated method, get the json from request body (params.get("body")), parse it using GSON or any other JSON library, and store the pojo in the request object (request.args.put(name, pojo)). Later in the controller method get the pojo from request args (request.args.get(name)). You can define custom annotations to limit this behaviour.

A good implementation would be creating a base controller class with @Before annotation and making this process generic using types.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM