-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-judge0-json.java
More file actions
49 lines (42 loc) · 1.62 KB
/
Copy pathtest-judge0-json.java
File metadata and controls
49 lines (42 loc) · 1.62 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
41
42
43
44
45
46
47
48
49
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.*;
class Judge0SubmissionRequest {
public String source_code;
public Integer language_id;
public String stdin;
public String expected_output;
public Double cpu_time_limit;
public Integer memory_limit;
public Judge0SubmissionRequest(String source_code, Integer language_id, String stdin,
String expected_output, Double cpu_time_limit, Integer memory_limit) {
this.source_code = source_code;
this.language_id = language_id;
this.stdin = stdin;
this.expected_output = expected_output;
this.cpu_time_limit = cpu_time_limit;
this.memory_limit = memory_limit;
}
}
public class TestJudge0Json {
public static void main(String[] args) throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
List<Judge0SubmissionRequest> submissions = new ArrayList<>();
submissions.add(new Judge0SubmissionRequest(
"print(\"hello\")",
71,
"",
"hello",
2.0,
128000
));
// 현재 코드처럼 Map으로 감싸기
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("submissions", submissions);
String jsonString = objectMapper.writeValueAsString(requestBody);
System.out.println("Generated JSON:");
System.out.println(jsonString);
// Pretty print
System.out.println("\nPretty JSON:");
System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(requestBody));
}
}