0

I am getting acquainted to Spring and its ecosystem. Working with Spring RESTful services, I came across representations.

{"id":1,"content":"Hello, World!"}

A simple representation

Working in a Java code base, I am trying to understand the difference between representations and beans.

Reading Spring's introduction to RESTful WebServices (link), I understand that representations are input/output of a RESTful Service Endpoint (JSON in the above example) which is very similar to a java bean. However, Java Bean is a standard (SO article).

Most, if not all, introduction to REST articles use the term representation without defining it. (spring's introduction to rest, restful architecutre 101, etc). The best definition I found so far (reference) states that;

A representation is a sequence of bytes, plus representation metadata to describe those bytes. Other commonly used but less precise names for a representation include: document, file, and HTTP message entity, instance, or variant.

Although it sounds like a complex datamodel, it can be broken down to a Java bean, so to reiterate my question, are representations and beans essentially the same thing especially in the context of Spring RESTful Services?

Lordbalmon
  • 1,634
  • 1
  • 14
  • 31

1 Answers1

1

Don't think they essentially refer to the same concept.

Representation in RESTful API just mean the response formats .Let 's say an API supports returning JSON , XML and plaintext , we say the API response has 3 representations. Which representations (JSON , XML or plaintext) will be returned depending on the Accept request header.

During the implementation , we normally use a JavaBean/POJO to represent the response. By using some library such as Jackson , the same JavaBean/POJO can be converted to different representations such as JSON and XML.

Ken Chan
  • 84,777
  • 26
  • 143
  • 172