Revize 56837af0
Přidáno uživatelem Jan Havlíček před asi 4 roky(ů)
project/Deserializer/src/jdeserialize/instance.java | ||
---|---|---|
26 | 26 |
this.fielddata = new HashMap<classdesc, Map<field, Object>>(); |
27 | 27 |
} |
28 | 28 |
|
29 |
|
|
29 | 30 |
public @Override String toJson(String indentation, Map<classdesc, Map<field, Object>> fielddata, Map<String, String> formatting) |
30 | 31 |
{ |
31 |
StringBuffer sb = new StringBuffer(); |
|
32 |
String val = ""; |
|
33 |
|
|
34 |
sb.append("{" + formatting.get("lineBreak")); |
|
35 |
|
|
36 |
indentation += formatting.get("indent"); |
|
37 |
|
|
38 |
// ClassName |
|
39 |
sb.append(indentation).append("class ").append(classdesc.name); |
|
40 |
// extends |
|
41 |
if (classdesc.superclass != null) { |
|
42 |
sb.append(" extends ").append(classdesc.superclass.name); |
|
43 |
} |
|
44 |
// implements |
|
45 |
if (classdesc.interfaces != null) { |
|
46 |
sb.append(" implements "); |
|
47 |
for (String str : classdesc.interfaces) { |
|
48 |
sb.append(str); |
|
49 |
} |
|
50 |
} |
|
51 |
sb.append(" : {"); // ending of first line |
|
52 |
|
|
53 |
indentation += formatting.get("indent"); |
|
54 |
|
|
55 |
for (field f : classdesc.fields) { |
|
56 |
// v this.fielddata najit element, jehoz key == classdesc |
|
57 |
// v tomto prvku fielddata najdu value (element) podle key == f |
|
58 |
// jeho value je chtena hodnota |
|
59 |
var locVal = this.fielddata.get(classdesc).get(f); |
|
60 |
|
|
61 |
if(locVal instanceof content) |
|
62 |
{ |
|
63 |
val = ((content)locVal).toJson(indentation, this.fielddata, formatting); |
|
64 |
} |
|
65 |
else { |
|
66 |
val = locVal.toString(); |
|
67 |
} |
|
68 |
|
|
69 |
sb.append(formatting.get("lineBreak")).append(indentation); |
|
70 |
sb.append("\"").append(f.name).append("\""); |
|
71 |
sb.append(" : "); |
|
72 |
sb.append(val); |
|
73 |
|
|
74 |
if (!f.equals(classdesc.fields[classdesc.fields.length - 1])) { |
|
75 |
sb.append(", "); |
|
76 |
} |
|
77 |
} |
|
78 |
indentation = indentation.substring(0, indentation.length() - 1); |
|
79 |
|
|
80 |
sb.append(formatting.get("lineBreak")).append(indentation).append("}"); |
|
81 |
|
|
82 |
if(classdesc.superclass != null) |
|
83 |
{ |
|
84 |
indentation = indentation.substring(0, indentation.length() - 1); |
|
85 |
sb.append(formatting.get("lineBreak") + "}"); |
|
86 |
sb.append(",").append(formatting.get("lineBreak")); |
|
87 |
sb.append(classdesc.superclass.toJson(indentation, this.fielddata, formatting)); |
|
88 |
} |
|
89 |
else |
|
90 |
{ |
|
91 |
indentation = indentation.substring(0, indentation.length() - 1); |
|
92 |
sb.append(formatting.get("lineBreak")).append(indentation).append("}"); |
|
93 |
} |
|
94 |
|
|
95 |
return sb.toString(); |
|
32 |
return this.classdesc.toJson(indentation, this.fielddata, formatting); |
|
96 | 33 |
} |
97 | 34 |
|
98 | 35 |
public String toString() { |
Také k dispozici: Unified diff
re#7868 HTML formatting implemented.
The Converter.convert returnes Pair<String, String> value.
The first is json, second html - for further work.