Performance: Message serialization
Message serialization affects the speed of data transfer between services and the time to process messages in the application.
public record User(String name, int age) {} // Using JSON with Jackson ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(user); outputStream.write(json.getBytes(StandardCharsets.UTF_8));
public class User { private String name; private int age; // getters and setters } // Using default Java serialization ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream()); out.writeObject(user);
| Pattern | CPU Cost | Message Size | Network Impact | Verdict |
|---|---|---|---|---|
| Default Java Serialization | High | Large (~50-100kb) | High latency and bandwidth use | [X] Bad |
| XML Serialization | Medium | Very Large | High latency and bandwidth use | [!] OK |
| JSON Serialization | Low | Medium | Efficient network use | [OK] Good |
| Binary Serialization (Protobuf) | Very Low | Small | Minimal latency and bandwidth | [OK] Good |
/user?
public record User(String name, int age) {}
@GetMapping("/user")
public User getUser() {
return new User("Alice", 30);
}@GetMapping("/product")
public Product getProduct() {
return new Product("Book", null);
}
public class Product {
private String name;
private String description;
public Product(String name, String description) {
this.name = name;
this.description = description;
}
public String getName() { return name; }
// Missing getter for description
}
What issue will occur when this endpoint is called?Pass the test and this pattern moves unknown