0
0
Spring Bootframework~10 mins

Message serialization in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to annotate a class for JSON serialization in Spring Boot.

Spring Boot
public class User {
    private String name;
    private int age;

    // getters and setters

    @[1]
    public String getName() {
        return name;
    }
}
Drag options to blanks, or click blank then click option'
AJsonProperty
BAutowired
CRequestMapping
DComponent
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Autowired instead of @JsonProperty
Confusing Spring annotations with Jackson annotations
2fill in blank
medium

Complete the code to convert a Java object to JSON string using Jackson's ObjectMapper.

Spring Boot
ObjectMapper mapper = new ObjectMapper();
String json = mapper.[1](user);
Drag options to blanks, or click blank then click option'
AwriteValueAsString
BreadValue
CconvertValue
DreadTree
Attempts:
3 left
💡 Hint
Common Mistakes
Using readValue which is for deserialization
Using readTree which returns a JsonNode
3fill in blank
hard

Fix the error in the code to deserialize JSON string to a Java object.

Spring Boot
User user = mapper.[1](json, User.class);
Drag options to blanks, or click blank then click option'
AwriteValueAsString
BwriteValue
CreadValue
DconvertValue
Attempts:
3 left
💡 Hint
Common Mistakes
Using writeValueAsString which is for serialization
Using convertValue incorrectly without JSON string
4fill in blank
hard

Fill both blanks to create a REST controller method that returns JSON response.

Spring Boot
@RestController
public class UserController {

    @GetMapping("/user")
    public [1] getUser() {
        User user = new User("Alice", 30);
        return user;
    }

    public void setUser(@[2] User user) {
        // setter
    }
}
Drag options to blanks, or click blank then click option'
AUser
Bvoid
CJsonProperty
DRequestBody
Attempts:
3 left
💡 Hint
Common Mistakes
Using void as return type for JSON response
Missing @RequestBody on setter parameter
5fill in blank
hard

Fill all three blanks to create a Map with filtered entries serialized to JSON.

Spring Boot
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()
    ));
Drag options to blanks, or click blank then click option'
A>
BtoMap
CtoUpperCase
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operator in filter
Using wrong collector method
Not converting keys to uppercase