Binding using POJOs

Note however you can just as easily write:

Binding JSON POJOs

  1. @Controller("/people")
  2. public class PersonController {
  3. Map<String, Person> inMemoryDatastore = new ConcurrentHashMap<>();
  4. @Post
  5. public HttpResponse<Person> save(@Body Person person) {
  6. inMemoryDatastore.put(person.getFirstName(), person);
  7. return HttpResponse.created(person);
  8. }
  9. }

Binding JSON POJOs

  1. @Controller("/people")
  2. class PersonController {
  3. ConcurrentHashMap<String, Person> inMemoryDatastore = [:]
  4. @Post
  5. HttpResponse<Person> save(@Body Person person) {
  6. inMemoryDatastore.put(person.getFirstName(), person)
  7. HttpResponse.created(person)
  8. }
  9. }

Binding JSON POJOs

  1. @Controller("/people")
  2. class PersonController {
  3. internal var inMemoryDatastore: MutableMap<String, Person> = ConcurrentHashMap()
  4. @Post
  5. fun save(@Body person: Person): HttpResponse<Person> {
  6. inMemoryDatastore[person.firstName] = person
  7. return HttpResponse.created(person)
  8. }
  9. }

Micronaut will only execute your method once the data has been read in a non-blocking manner.

The output produced by Jackson can be customized in a variety of manners, from defining Jackson modules to using Jackson’s annotations