Revize 02390102
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 |
public @Override String toJson(String indentation, Map<classdesc, Map<field, Object>> fielddata) |
|
29 |
public @Override String toJson(String indentation, Map<classdesc, Map<field, Object>> fielddata, Map<String, String> formatting)
|
|
30 | 30 |
{ |
31 | 31 |
StringBuffer sb = new StringBuffer(); |
32 | 32 |
String val = ""; |
33 | 33 |
|
34 |
sb.append("{\n");
|
|
34 |
sb.append("{" + formatting.get("lineBreak"));
|
|
35 | 35 |
|
36 |
indentation += "\t";
|
|
36 |
indentation += formatting.get("indent");
|
|
37 | 37 |
|
38 | 38 |
// ClassName |
39 | 39 |
sb.append(indentation).append("class ").append(classdesc.name); |
... | ... | |
50 | 50 |
} |
51 | 51 |
sb.append(" : {"); // ending of first line |
52 | 52 |
|
53 |
indentation += "\t";
|
|
53 |
indentation += formatting.get("indent");
|
|
54 | 54 |
|
55 | 55 |
for (field f : classdesc.fields) { |
56 | 56 |
// v this.fielddata najit element, jehoz key == classdesc |
... | ... | |
60 | 60 |
|
61 | 61 |
if(locVal instanceof content) |
62 | 62 |
{ |
63 |
val = ((content)locVal).toJson(indentation, this.fielddata); |
|
63 |
val = ((content)locVal).toJson(indentation, this.fielddata, formatting);
|
|
64 | 64 |
} |
65 | 65 |
else { |
66 | 66 |
val = locVal.toString(); |
67 | 67 |
} |
68 | 68 |
|
69 |
sb.append("\n").append(indentation);
|
|
69 |
sb.append(formatting.get("lineBreak")).append(indentation);
|
|
70 | 70 |
sb.append("\"").append(f.name).append("\""); |
71 | 71 |
sb.append(" : "); |
72 | 72 |
sb.append(val); |
... | ... | |
77 | 77 |
} |
78 | 78 |
indentation = indentation.substring(0, indentation.length() - 1); |
79 | 79 |
|
80 |
sb.append("\n").append(indentation).append("}");
|
|
80 |
sb.append(formatting.get("lineBreak")).append(indentation).append("}");
|
|
81 | 81 |
|
82 | 82 |
if(classdesc.superclass != null) |
83 | 83 |
{ |
84 | 84 |
indentation = indentation.substring(0, indentation.length() - 1); |
85 |
sb.append("\n}");
|
|
86 |
sb.append(",\n");
|
|
87 |
sb.append(classdesc.superclass.toJson(indentation, this.fielddata)); |
|
85 |
sb.append(formatting.get("lineBreak") + "}");
|
|
86 |
sb.append(",").append(formatting.get("lineBreak"));
|
|
87 |
sb.append(classdesc.superclass.toJson(indentation, this.fielddata, formatting));
|
|
88 | 88 |
} |
89 | 89 |
else |
90 | 90 |
{ |
91 | 91 |
indentation = indentation.substring(0, indentation.length() - 1); |
92 |
sb.append("\n").append(indentation).append("}");
|
|
92 |
sb.append(formatting.get("lineBreak")).append(indentation).append("}");
|
|
93 | 93 |
} |
94 | 94 |
|
95 | 95 |
return sb.toString(); |
Také k dispozici: Unified diff
#re#7868 Test - JSON format observed.