1/38
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is the default data format for structured data in RESTful services?
JSON (JavaScript Object Notation).
Why is JSON preferred over XML in REST?
It's simpler, human-readable, widely supported, and doesn't require extra configuration in Spring.
REST vs SOAP for structured data
How can you manually create a JSON object in Java?
Using JsonObjectBuilder
from javax.json
:
java
Json.createObjectBuilder().add("Fruit", "Lemon").build();
What's a better alternative to manually building JSON in Spring?
Returning Java objects and letting Spring (with Jackson) auto-convert them to JSON.
What does Spring use to automatically convert Java objects to JSON?
Jackson (a JSON serialization library).
What must a Java class have for Spring to serialize it to JSON?
Getter methods (getX()
) for each field you want to include.
Do setter methods matter for JSON serialization?
No, they only matter for deserialization (receiving JSON).
Can immutable classes (with constructors and final fields) be serialized?
Yes, as long as they have getters and a constructor.
Can Java Records be used for JSON data classes?
Yes! Records are supported out of the box by Jackson.
What does produces=MediaType.APPLICATION_JSON_VALUE
do?
Explicitly declares that the method returns JSON.
What happens if you set produces=MediaType.APPLICATION_XML_VALUE
without configuration?
You get a 500 Internal Server Error
.
How do you receive JSON data in a POST request?
Use @PostMapping(..., consumes=MediaType.APPLICATION_JSON_VALUE)
with @RequestBody
What library is used in Java clients to convert between JSON and Java objects?
Jackson, using ObjectMapper
.
What Maven dependency do you need to add Jackson to your project?
What class is used to build HTTP requests in Java?
HttpRequest
from java.net.http
.
How do you deserialize a list of objects from JSON using Jackson?
How do you send a POST request with JSON in the body?
Convert the object with objectMapper.writeValueAsString(obj)
and use BodyPublishers.ofString(...)
.
What class lets you customize HTTP status codes and headers in Spring?
ResponseEntity<T>
How do you return a 200 OK response with data?
return ResponseEntity.ok(data);
How do you return a 404 Not Found response?
return ResponseEntity.notFound().build();
How do you return a 409 Conflict response?
return ResponseEntity.status(HttpStatus.CONFLICT).build();
How do you return a 204 No Content response?
return ResponseEntity.noContent().build();
Can you add headers to a ResponseEntity
?
Yes, using .header("key", "value")
.
How do you check the HTTP status code of a response in Java?
response.statusCode()
What is Optional<T>
used for in Java?
To represent a value that may or may not be present (instead of using null
).
How do you create a non-empty Optional?
Optional.of(data)
How do you create an empty Optional?
Optional.empty()
How do you create an Optional that might be null?
Optional.ofNullable(data)
How do you use a lambda to process an Optional if it’s present?
myOptional.ifPresent(data -> doSomething(data));
How do you handle both present and empty cases in an Optional?
Why not use Optional for everything (e.g. addStar
)?
For binary success/failure cases, returning a boolean
is clearer.
What is OpenAPI?
A standard for describing REST APIs in a machine-readable format.
What dependency do you need to add to enable OpenAPI in Spring Boot?
What URL gives you the OpenAPI JSON spec for your API?
What URL shows the Swagger UI web interface?
What can Swagger UI be used for?
Browsing, documenting, and testing API endpoints interactively.
Can you import OpenAPI specs into Postman?
Yes — Postman supports OpenAPI v3 import.
Does SoapUI support OpenAPI v3?
No — only the paid version does; free version supports OpenAPI v2 only.