Revize 961cd43a
Přidáno uživatelem Michal Horký před více než 4 roky(ů)
demo_mh/Deserializer/src/deserialize/Variable.java | ||
---|---|---|
1 | 1 |
package deserialize; |
2 | 2 |
|
3 |
import org.json.simple.JSONObject; |
|
3 |
import java.util.Arrays; |
|
4 |
|
|
5 |
import org.codehaus.jackson.node.ObjectNode; |
|
4 | 6 |
|
5 | 7 |
public class Variable { |
6 | 8 |
|
... | ... | |
8 | 10 |
private String variable; |
9 | 11 |
private String typeName; |
10 | 12 |
private Object value = null; |
13 |
private Object array[] = null; |
|
11 | 14 |
|
12 | 15 |
public Variable(char type, String variable, String typeName) { |
13 | 16 |
this.type = type; |
... | ... | |
34 | 37 |
} |
35 | 38 |
|
36 | 39 |
public boolean isValueSet() { |
37 |
return value != null; |
|
40 |
return value != null || array != null;
|
|
38 | 41 |
} |
39 | 42 |
|
40 | 43 |
public void setValue(Object value) { |
41 | 44 |
this.value = value; |
42 | 45 |
} |
43 | 46 |
|
44 |
@SuppressWarnings("unchecked") |
|
45 |
public void putToJSON(JSONObject obj) { |
|
46 |
if (value != null) { |
|
47 |
if (value.getClass().toString().equals(ClassDescription.class.toString())) { |
|
47 |
public void setValue(Object array[]) { |
|
48 |
this.array = array; |
|
49 |
} |
|
50 |
|
|
51 |
public void putToJson(ObjectNode node) { |
|
52 |
if (value != null || array != null) { |
|
53 |
if (value != null && value.getClass().toString().equals(ClassDescription.class.toString())) { |
|
48 | 54 |
ClassDescription desc = (ClassDescription) value; |
49 |
obj.put(variable, desc.getJSONObject()); |
|
50 |
} else { |
|
51 |
obj.put(variable, value); |
|
55 |
node.put(variable, desc.getJsonNode()); |
|
56 |
} else if (value != null) { |
|
57 |
node.put(variable, value.toString()); |
|
58 |
} else if (array != null) { |
|
59 |
node.put(variable, Arrays.toString(array)); |
|
52 | 60 |
} |
53 | 61 |
} else { |
54 |
obj.put(variable, "NON_IMPLEMENTED");
|
|
62 |
node.put(variable, "NOT_IMPLEMENTED");
|
|
55 | 63 |
} |
56 | 64 |
} |
57 | 65 |
|
... | ... | |
72 | 80 |
if (value.getClass().toString().equals(ClassDescription.class.toString())) { |
73 | 81 |
ClassDescription desc = (ClassDescription) value; |
74 | 82 |
result += desc.toString(); |
75 |
} else { |
|
83 |
} else if (value != null) {
|
|
76 | 84 |
result += value; |
85 |
} else if (array != null) { |
|
86 |
result += Arrays.toString(array); |
|
77 | 87 |
} |
78 | 88 |
} |
79 | 89 |
|
Také k dispozici: Unified diff
#7794
Rozpoznávání polí, úprava JSON