Skip to content

Commit 714496d

Browse files
committed
Content instance support with Gson serializer
1 parent 60d92e4 commit 714496d

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

common/src/main/java/fr/epsilon/common/crd/EpsilonInstanceCRD.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public EInstance getInstance() {
5555
if (getStatus() != null) {
5656
String template = getStatus().getTemplate();
5757

58-
String content = getStatus().getContent();
58+
Object content = getStatus().getContent();
5959

6060
boolean hub = getStatus().isHub();
6161

common/src/main/java/fr/epsilon/common/crd/EpsilonInstanceCRDStatus.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class EpsilonInstanceCRDStatus {
3434
private Boolean hub = null;
3535

3636
@SerializedName(SERIALIZED_NAME_CONTENT)
37-
private String content = null;
37+
private Object content = null;
3838

3939
@SerializedName(SERIALIZED_NAME_STATE)
4040
private EState state = null;
@@ -61,7 +61,7 @@ public Boolean isHub() {
6161
return hub;
6262
}
6363

64-
public String getContent() {
64+
public Object getContent() {
6565
return content;
6666
}
6767

common/src/main/java/fr/epsilon/common/instance/EInstance.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package fr.epsilon.common.instance;
22

3+
import com.google.gson.Gson;
34
import fr.epsilon.common.Epsilon;
45

56
public class EInstance {
7+
private static final Gson gson = new Gson();
8+
69
private String name;
710
private String template;
811

9-
private String content;
12+
private Object content;
1013

1114
private boolean hub;
1215

@@ -18,15 +21,20 @@ public class EInstance {
1821

1922
private String ip;
2023

21-
public EInstance(String name, String template, String content, boolean hub, EType type, EState state, int slots, int online_count, String ip) {
24+
public EInstance(String name, String template, Object content, boolean hub, EType type, EState state, int slots, int online_count, String ip) {
2225
this.name = name;
2326
this.template = template;
27+
2428
this.content = content;
29+
2530
this.hub = hub;
31+
2632
this.type = type;
2733
this.state = state;
34+
2835
this.slots = slots;
2936
this.online_count = online_count;
37+
3038
this.ip = ip;
3139
}
3240

@@ -38,8 +46,8 @@ public String getTemplate() {
3846
return template;
3947
}
4048

41-
public String getContent() {
42-
return content;
49+
public <T> T getContent(Class<T> classType) {
50+
return gson.fromJson(gson.toJson(content), classType);
4351
}
4452

4553
public boolean isHub() {

common/src/main/java/fr/epsilon/common/instance/EInstanceModule.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,16 @@ public CompletableFuture<EInstance[]> getInstances(EType type) {
8686
}
8787

8888
public boolean openInstance(String template) {
89+
return openInstance(template, new Object());
90+
}
91+
92+
public <T> boolean openInstance(String template, T content) {
93+
MediaType media = MediaType.parse("application/json; charset=utf-8");
94+
RequestBody body = RequestBody.create(gson.toJson(content), media);
95+
8996
Request request = new Request.Builder()
9097
.url(EpsilonEnvironments.getEpsilonURL("/instance/create/" + template))
91-
.post(RequestBody.create(new byte[]{}))
98+
.post(body)
9299
.build();
93100

94101
try {

0 commit comments

Comments
 (0)