-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathOrderProcessor.java
More file actions
40 lines (28 loc) · 1.05 KB
/
OrderProcessor.java
File metadata and controls
40 lines (28 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package ironhack;
import com.google.gson.Gson;
public class OrderProcessor {
public static void main(String[] args) {
OrderProcessor processor = new OrderProcessor();
processor.processOrder();
}
Gson gson = new Gson();
String jsonOrder= """
{
"orderId": "12345",
"customerId": "67890",
"items": [
{"productId": "111", "name": "Laptop", "quantity": 2, "price": 10.0},
{"productId": "222", "name": "Camera", "quantity": 1, "price": 20.0}
]
}
""";
Order order = gson.fromJson(jsonOrder, Order.class);
public void processOrder () {
System.out.println("Processing order: " + order.getOrderId());
System.out.println("Customer ID: " + order.getCustomerId());
System.out.println("Items:");
for (Item item : order.getItems()) {
System.out.println("- " + item.getName() + ": " + item.getQuantity() + " x $" + item.getPrice());
}
}
}