-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathExampleGsonDeserialization.java
More file actions
98 lines (70 loc) · 2.56 KB
/
ExampleGsonDeserialization.java
File metadata and controls
98 lines (70 loc) · 2.56 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package modules.examples;
import common.parallelization.CallbackReceiver;
import modules.CharPipe;
import modules.ModuleImpl;
import modules.InputPort;
import modules.OutputPort;
import java.util.Properties;
//Gson import
import com.google.gson.Gson;
import base.workbench.ModuleRunner;
public class ExampleGsonDeserialization extends ModuleImpl {
// Main method for stand-alone execution
public static void main(String[] args) throws Exception {
ModuleRunner.runStandAlone(ExampleGsonDeserialization.class, args);
}
//Add property keys:
/* no property keys */
//Add properties variables:
/* no property variables */
//Add variables:
private String inputJSON;
//Add I/O labels
private final String INPUTID = "JSON";
private final String OUTPUTID = "String";
//Add constructors:
public ExampleGsonDeserialization (CallbackReceiver callbackReceiver,
Properties properties) throws Exception {
super(callbackReceiver, properties);
//Add description for properties
/* no property keys available */
//Add default values
this.getPropertyDefaultValues().put(ModuleImpl.PROPERTYKEY_NAME,
"Example Gson Deserialization Module");
//Define I/O
InputPort inputPort = new InputPort (INPUTID, "serialized JSON input", this);
inputPort.addSupportedPipe(CharPipe.class);
OutputPort outputPort = new OutputPort(OUTPUTID, "deserialized string output", this);
outputPort.addSupportedPipe(CharPipe.class);
super.addInputPort(inputPort);
super.addOutputPort(outputPort);
//Add module description
this.setDescription("Example Module: Deserializing a test string in JSON format.<br/> Output is plain text.");
// You can override the automatic category selection (for example if a module is to be shown in "deprecated")
//this.setCategory("Examples");
}
//Add methods:
//Add process() method:
@Override
public boolean process() throws Exception {
//Read JSON from input pipe
Gson gson = new Gson ();
this.inputJSON = gson.fromJson(this.getInputPorts().get(INPUTID).getInputReader(), String.class);
//Write plain string to output pipe
this.getOutputPorts().get(OUTPUTID).outputToAllCharPipes(this.inputJSON);
//Close outputs
this.closeAllOutputs();
//Success
return true;
}
//Add applyProperties() method:
@Override
public void applyProperties() throws Exception {
// Set defaults for properties not yet set
super.setDefaultsIfMissing();
// Apply own properties
/* no own properties */
// Apply parent object's properties (just the name variable actually)
super.applyProperties();
}
}