Complete the code to annotate a class for JSON serialization in Spring Boot.
public class User { private String name; private int age; // getters and setters @[1] public String getName() { return name; } }
The @JsonProperty annotation marks a method or field to be included in JSON serialization.
Complete the code to convert a Java object to JSON string using Jackson's ObjectMapper.
ObjectMapper mapper = new ObjectMapper();
String json = mapper.[1](user);The writeValueAsString method converts a Java object to a JSON string.
Fix the error in the code to deserialize JSON string to a Java object.
User user = mapper.[1](json, User.class);
The readValue method deserializes JSON string into a Java object.
Fill both blanks to create a REST controller method that returns JSON response.
@RestController public class UserController { @GetMapping("/user") public [1] getUser() { User user = new User("Alice", 30); return user; } public void setUser(@[2] User user) { // setter } }
The method returns a User object which Spring Boot automatically serializes to JSON.
The @RequestBody annotation is used on setter to bind JSON request body to the method parameter.
Fill all three blanks to create a Map with filtered entries serialized to JSON.
Map<String, Integer> result = Map.of("a", 1, "b", 2, "c", 3); Map<String, Integer> filtered = result.entrySet().stream() .filter(e -> e.getValue() [1] 1) .collect(Collectors.[2]( e -> e.getKey().[3](), e -> e.getValue() ));
The filter keeps entries with values greater than 1.
The collector gathers entries into a Map.
The keys are converted to uppercase strings.