Post

JSON Serialization/Deserialization, @RequestBody, @ModelAttribute

JSON Serialization/Deserialization, @RequestBody, @ModelAttribute

This post was migrated from Tistory. You can find the original here.

On JSON conversion

Serialization - converting to JSON

Deserialization - converting to a Java object

+) When returning an entity instead of a response DTO, if the entity has no @Getter, it won’t be serialized.

@RequestBody

  • Works even without a @Setter or a constructor (a default constructor is still required).
  • At least one of getter or setter must be defined so the field names can be determined for data binding.
  • The annotation cannot be omitted.

@ModelAttribute

  • Requires a @Setter or a constructor to work.
  • Can’t handle data that isn’t in Query String or Form format (application/json won’t work).
  • The annotation can be omitted.

References

https://tecoble.techcourse.co.kr/post/2021-05-11-requestbody-modelattribute/

This post is licensed under CC BY-NC 4.0 by the author.