Skip to content
This repository was archived by the owner on Jun 12, 2020. It is now read-only.

Latest commit

 

History

History
47 lines (37 loc) · 1.2 KB

File metadata and controls

47 lines (37 loc) · 1.2 KB

Analog Web Framework Jackson Plugin

Build Status

This plugin enables parse JSON format request.(application/json)

Also rendering JSON using Jackson's ObjectMapper.

Example

import static org.analogweb.core.response.BasicResponses.json;

import org.analogweb.annotation.Route;
import org.analogweb.annotation.Get;
import org.analogweb.annotation.Post;
import org.analogweb.annotation.RequestFormats;
import org.analogweb.core.MediaTypes;
import org.analogweb.core.response.Json;
import org.analogweb.jackson.JsonType;

@Route("/")
public class Hello {

  @Route("json")
  // Add Content-Type limitation. (Response 415 when invalid Content-Type detected.)
  // Without this annotation there is no Content-Type limitation. (Argument is null.)
  @RequestFormats(MediaTypes.APPLICATION_JSON)
  @Post
  public String postJson(@JsonType Bean bean) {
     // Obtain requested JSON as object.
     ...
  }

  @Route("json")
  @Get
  public Json getJson() {
    ...
    Bean bean
    ...
    // Response JSON using Jackson's ObjectMapper.
    return json(bean)
  }

}