Revize a0511590
Přidáno uživatelem Jan Havlíček před asi 5 roky(ů)
project/Deserializer/bcha.json | ||
---|---|---|
2 | 2 |
class samples.ok.Simple : { |
3 | 3 |
"testDouble" : 1.0, |
4 | 4 |
"testInt" : 123, |
5 |
"intArray" : [ 5, 10, 15 ],
|
|
5 |
"intArray" : [ ], |
|
6 | 6 |
"locInnerClassInstance" : { |
7 |
class samples.ok.Inner : {
|
|
8 |
"vnitrni" : "INNER STRING AM I"
|
|
9 |
}
|
|
10 |
},
|
|
7 |
class samples.ok.Inner : { |
|
8 |
"vnitrni" : "INNER STRING AM I" |
|
9 |
} |
|
10 |
}, |
|
11 | 11 |
"localEnum" : LOW, |
12 | 12 |
"pozdrav" : "AHOJ", |
13 | 13 |
"stringArray" : [ "A", "B", "C" ] |
project/Deserializer/src/Converter.java | ||
---|---|---|
59 | 59 |
{ |
60 | 60 |
if(cnt != null) |
61 | 61 |
{ |
62 |
json += cnt.toString();
|
|
62 |
json += cnt.toJson("");
|
|
63 | 63 |
} |
64 | 64 |
} |
65 | 65 |
|
66 | 66 |
System.out.println("Task completed."); |
67 | 67 |
|
68 | 68 |
//just for tests |
69 |
//System.out.println(json);
|
|
69 |
System.out.println(json); |
|
70 | 70 |
|
71 | 71 |
return json; |
72 | 72 |
} catch (IOException e) { |
project/Deserializer/src/jdeserialize/arrayobj.java | ||
---|---|---|
1 | 1 |
package jdeserialize; |
2 | 2 |
|
3 | 3 |
/** |
4 |
* <p>Represents an array instance, including the values the comprise the array. </p> |
|
4 |
* <p> |
|
5 |
* Represents an array instance, including the values the comprise the array. |
|
6 |
* </p> |
|
5 | 7 |
* |
6 |
* <p>Note that in arrays of primitives, the classdesc will be named "[x", where x is the |
|
7 |
* field type code representing the primitive type. See jdeserialize.resolveJavaType() |
|
8 |
* for an example of analysis/generation of human-readable names from these class names.</p> |
|
8 |
* <p> |
|
9 |
* Note that in arrays of primitives, the classdesc will be named "[x", where x |
|
10 |
* is the field type code representing the primitive type. See |
|
11 |
* jdeserialize.resolveJavaType() for an example of analysis/generation of |
|
12 |
* human-readable names from these class names. |
|
13 |
* </p> |
|
9 | 14 |
*/ |
10 | 15 |
public class arrayobj extends contentbase { |
11 | 16 |
/** |
... | ... | |
24 | 29 |
this.classdesc = cd; |
25 | 30 |
this.data = data; |
26 | 31 |
} |
27 |
public String toString() { |
|
32 |
|
|
33 |
public @Override String toJson(String indentation) { |
|
28 | 34 |
StringBuilder sb = new StringBuilder(); |
29 | 35 |
sb.append("[ "); |
30 |
for(Object el : this.data) |
|
31 |
{ |
|
32 |
sb.append(el.toString()); |
|
33 |
if(!el.equals(this.data.get(this.data.size()-1))) |
|
34 |
{ |
|
35 |
sb.append(", "); |
|
36 |
|
|
37 |
for (Object el : this.data) { |
|
38 |
if (el != null && el instanceof content) { |
|
39 |
sb.append(((content)el).toJson(indentation)); |
|
40 |
// el null! |
|
41 |
if (!el.equals(this.data.get(this.data.size() - 1))) { |
|
42 |
sb.append(", "); |
|
43 |
} |
|
36 | 44 |
} |
37 | 45 |
} |
38 | 46 |
sb.append(" ]"); |
39 | 47 |
return sb.toString(); |
40 | 48 |
} |
41 |
} |
|
42 | 49 |
|
50 |
public String toString() { |
|
51 |
return "[array " + jdeserialize.hex(handle) + " classdesc " + classdesc.toString() + ": " + data.toString() |
|
52 |
+ "]"; |
|
53 |
} |
|
54 |
} |
project/Deserializer/src/jdeserialize/content.java | ||
---|---|---|
64 | 64 |
* @param value the new value to use |
65 | 65 |
*/ |
66 | 66 |
public void setIsExceptionObject(boolean value); |
67 |
|
|
68 |
public String toJson(String indentation); |
|
67 | 69 |
} |
68 | 70 |
|
project/Deserializer/src/jdeserialize/contentbase.java | ||
---|---|---|
24 | 24 |
} |
25 | 25 |
public void validate() throws ValidityException { |
26 | 26 |
} |
27 |
|
|
28 |
public @Override String toJson(String indetation) |
|
29 |
{ |
|
30 |
return this.toString(); |
|
31 |
} |
|
27 | 32 |
} |
28 | 33 |
|
project/Deserializer/src/jdeserialize/enumobj.java | ||
---|---|---|
31 | 31 |
this.classdesc = cd; |
32 | 32 |
this.value = so; |
33 | 33 |
} |
34 |
public String toString() {
|
|
34 |
public @Override String toJson(String indetation) {
|
|
35 | 35 |
return this.value.value; |
36 | 36 |
} |
37 |
|
|
38 |
public String toString(){ |
|
39 |
return "[enum " + jdeserialize.hex(handle) + ": " + value.value + "]"; |
|
40 |
} |
|
37 | 41 |
} |
project/Deserializer/src/jdeserialize/instance.java | ||
---|---|---|
26 | 26 |
this.fielddata = new HashMap<classdesc, Map<field, Object>>(); |
27 | 27 |
} |
28 | 28 |
|
29 |
public String toString() { |
|
29 |
public @Override String toJson(String indentation) |
|
30 |
{ |
|
30 | 31 |
StringBuffer sb = new StringBuffer(); |
32 |
String val = ""; |
|
33 |
|
|
34 |
/*if (classdesc.getType() == contenttype.CLASSDESC && !instance.indentedClasses.contains(classdesc.name)) {*/ |
|
35 |
indentation += "\t"; |
|
36 |
/* instance.indentedClasses.add(classdesc.name); |
|
37 |
}*/ |
|
31 | 38 |
|
32 | 39 |
// ClassName |
33 |
sb.append("{\n\tclass ").append(classdesc.name);
|
|
40 |
sb.append("{\n").append(indentation).append("class ").append(classdesc.name);
|
|
34 | 41 |
// extends |
35 | 42 |
if (classdesc.superclass != null) { |
36 | 43 |
sb.append(" extends ").append(classdesc.superclass.name); |
... | ... | |
48 | 55 |
// v this.fielddata najit element, jehoz key == classdesc |
49 | 56 |
// v tomto prvku fielddata najdu value (element) podle key == f |
50 | 57 |
// jeho value je chtena hodnota |
51 |
var val = this.fielddata.get(classdesc).get(f).toString(); |
|
52 |
sb.append("\n\t\t"); |
|
53 |
// Datový typ není potřeba - json jej nepoužívá! |
|
54 |
sb.append("\"")./* append(f.type.getJavaType()).append(" "). */append(f.name).append("\""); |
|
58 |
|
|
59 |
var locVal = this.fielddata.get(classdesc).get(f); |
|
60 |
|
|
61 |
if(locVal instanceof content) |
|
62 |
{ |
|
63 |
val = ((content)locVal).toJson(indentation); |
|
64 |
} |
|
65 |
else { |
|
66 |
val = locVal.toString(); |
|
67 |
} |
|
68 |
|
|
69 |
sb.append("\n\t").append(indentation); |
|
70 |
sb.append("\"").append(f.name).append("\""); |
|
55 | 71 |
sb.append(" : "); |
56 | 72 |
sb.append(val); |
57 | 73 |
|
... | ... | |
60 | 76 |
} |
61 | 77 |
} |
62 | 78 |
|
63 |
sb.append("\n\t}\n}");
|
|
79 |
sb.append("\n").append(indentation).append("}\n}");
|
|
64 | 80 |
|
81 |
/*if (classdesc.getType() == contenttype.CLASSDESC && instance.indentedClasses.contains(classdesc.name)) {*/ |
|
82 |
indentation.replaceFirst("\t", ""); |
|
83 |
/*instance.indentedClasses.remove(classdesc.name); |
|
84 |
}*/ |
|
85 |
|
|
86 |
return sb.toString(); |
|
87 |
} |
|
88 |
|
|
89 |
public String toString() { |
|
90 |
StringBuffer sb = new StringBuffer(); |
|
91 |
sb.append(classdesc.name).append(' ').append("_h").append(jdeserialize.hex(handle)) |
|
92 |
.append(" = r_").append(jdeserialize.hex(classdesc.handle)).append("; "); |
|
93 |
//sb.append("// [instance " + jdeserialize.hex(handle) + ": " + jdeserialize.hex(classdesc.handle) + "/" + classdesc.name).append("]"); |
|
65 | 94 |
return sb.toString(); |
66 | 95 |
} |
67 | 96 |
|
project/Deserializer/src/jdeserialize/jdeserialize.java | ||
---|---|---|
837 | 837 |
break; |
838 | 838 |
} |
839 | 839 |
content c = read_Content(tc, dis, true); |
840 |
System.out.println("read: " + c.toString()); |
|
840 |
//System.out.println("read: " + c.toString());
|
|
841 | 841 |
if(c != null && c.isExceptionObject()) { |
842 | 842 |
c = new exceptionstate(c, lis.getRecordedData()); |
843 | 843 |
} |
project/Deserializer/src/jdeserialize/stringobj.java | ||
---|---|---|
15 | 15 |
} |
16 | 16 |
return x; |
17 | 17 |
} |
18 |
public String toString() { |
|
18 |
|
|
19 |
public @Override String toJson(String indetation) |
|
20 |
{ |
|
19 | 21 |
return "\"" + this.value + "\""; |
20 | 22 |
} |
23 |
|
|
24 |
public String toString() { |
|
25 |
return "[String " + jdeserialize.hex(handle) + ": \"" + value + "\"]"; |
|
26 |
} |
|
21 | 27 |
/** |
22 | 28 |
* Constructor. |
23 | 29 |
* |
Také k dispozici: Unified diff
#re#7831 Indetation problems. toString left, new toJson method
Not working yet