Revize 4d741e6d
Přidáno uživatelem Jan Havlíček před téměř 5 roky(ů)
project/Deserializer/src/jdeserialize/arrayobj.java | ||
---|---|---|
44 | 44 |
if (el != null) { |
45 | 45 |
if (el instanceof content) { |
46 | 46 |
if(!bracketInserted){ |
47 |
sb.append("\n").append(indentation).append("[ \n");
|
|
47 |
sb.append(NEW_LINE).append(indentation).append("[ " + NEW_LINE);
|
|
48 | 48 |
bracketInserted = true; |
49 |
indentation += "\t";
|
|
49 |
indentation += INDENT;
|
|
50 | 50 |
} |
51 | 51 |
sb.append(((content) el).toJson(indentation, fielddata, false)); |
52 | 52 |
|
53 | 53 |
if (!isLast) { |
54 |
sb.append(",\n");
|
|
54 |
sb.append("," + NEW_LINE);
|
|
55 | 55 |
} |
56 | 56 |
else{ |
57 |
indentation = indentation.replaceFirst("\t", "");
|
|
58 |
sb.append("\n").append(indentation).append("]");
|
|
57 |
indentation = indentation.replaceFirst(INDENT, "");
|
|
58 |
sb.append(NEW_LINE).append(indentation).append("]");
|
|
59 | 59 |
bracketInserted = false; |
60 | 60 |
} |
61 | 61 |
}else{ |
project/Deserializer/src/jdeserialize/classdesc.java | ||
---|---|---|
252 | 252 |
sb.append(indentation); |
253 | 253 |
} |
254 | 254 |
|
255 |
sb.append("{\n");
|
|
256 |
indentation += "\t";
|
|
255 |
sb.append("{" + NEW_LINE);
|
|
256 |
indentation += INDENT;
|
|
257 | 257 |
|
258 | 258 |
sb.append(indentation).append("class ").append(this.name); |
259 | 259 |
|
... | ... | |
261 | 261 |
this.interfacesToJson(sb, this.interfaces); |
262 | 262 |
|
263 | 263 |
sb.append(" : {"); // ending of first line |
264 |
indentation += "\t";
|
|
264 |
indentation += INDENT;
|
|
265 | 265 |
|
266 | 266 |
//iterating through fields and converts them into json string |
267 | 267 |
for (field locField : this.fields) { |
... | ... | |
277 | 277 |
fieldJsonValue = locVal.toString(); |
278 | 278 |
} |
279 | 279 |
|
280 |
String locString = "\n" + indentation + "\"" + locField.name + "\"" + " : " + fieldJsonValue;
|
|
280 |
String locString = NEW_LINE + indentation + "\"" + locField.name + "\"" + " : " + fieldJsonValue;
|
|
281 | 281 |
sb.append(locString); |
282 | 282 |
|
283 | 283 |
if (!locField.equals(this.fields[this.fields.length - 1])) { |
... | ... | |
285 | 285 |
} |
286 | 286 |
} |
287 | 287 |
|
288 |
indentation = indentation.replaceFirst("\t", ""); |
|
289 |
sb.append("\n").append(indentation).append("}"); |
|
288 |
closingJsonSeq(sb, indentation); |
|
290 | 289 |
|
291 | 290 |
//recursively call toJson for superclass if presented |
292 | 291 |
if (this.superclass != null) { |
293 |
indentation = indentation.replaceFirst("\t", ""); |
|
294 |
sb.append("\n").append(indentation).append("}"); |
|
295 |
sb.append("," + "\n"); |
|
292 |
sb.append("," + NEW_LINE); |
|
296 | 293 |
sb.append(this.superclass.toJson(indentation, fielddata, false)); |
297 |
} else { |
|
298 |
indentation = indentation.replaceFirst("\t", ""); |
|
299 |
sb.append("\n").append(indentation).append("}"); |
|
300 |
} |
|
294 |
} |
|
301 | 295 |
|
302 | 296 |
return sb.toString(); |
303 | 297 |
} |
304 | 298 |
|
299 |
/** |
|
300 |
* Removes the indentation, inserts new line and closing curly brackets in sb |
|
301 |
* Does this sequence twice for closing the classdesc toJson |
|
302 |
* |
|
303 |
* @param sb StringBuffer where the closing sequence will be appended |
|
304 |
* @param indentation Indentation to be changed |
|
305 |
*/ |
|
306 |
private void closingJsonSeq(StringBuffer sb, String indentation) |
|
307 |
{ |
|
308 |
indentation = indentation.replaceFirst(INDENT, ""); |
|
309 |
sb.append(NEW_LINE).append(indentation).append("}"); |
|
310 |
|
|
311 |
indentation = indentation.replaceFirst(INDENT, ""); |
|
312 |
sb.append(NEW_LINE).append(indentation).append("}"); |
|
313 |
} |
|
314 |
|
|
305 | 315 |
/** |
306 | 316 |
* Appends the extends clausule to the input StringBuffer. |
307 | 317 |
* Only if superclass presented |
project/Deserializer/src/jdeserialize/content.java | ||
---|---|---|
1 | 1 |
package jdeserialize; |
2 | 2 |
|
3 |
import java.util.HashMap; |
|
4 | 3 |
import java.util.Map; |
5 | 4 |
|
6 | 5 |
/** |
... | ... | |
16 | 15 |
* </p> |
17 | 16 |
*/ |
18 | 17 |
public interface content { |
18 |
//constants for toJson methods |
|
19 |
public static final String INDENT = "\t"; |
|
20 |
public static final String NEW_LINE = "\n"; |
|
21 |
|
|
19 | 22 |
/** |
20 | 23 |
* @return the type of instance represented by this object. |
21 | 24 |
*/ |
... | ... | |
73 | 76 |
* <p> |
74 | 77 |
* Analogy for toString method; however, outputs its string in json formatting. |
75 | 78 |
* Returns the exact json representation of object with indentation. |
76 |
* |
|
79 |
* </p>
|
|
77 | 80 |
* <p> |
78 | 81 |
* Inherited by multiple classes via contentbase, often calls itself for another object |
79 |
* |
|
82 |
* </p>
|
|
80 | 83 |
* @param indentation starting indentation for json output |
81 | 84 |
* @param fielddata used when calling this method for inner instances |
82 |
* so the instance has info about its variables |
|
85 |
* so the instance has info about its variables. |
|
86 |
* Instance info is saved in another content space than |
|
87 |
* info about its field variables, so it must be provided by parameter |
|
88 |
* to inner instances |
|
83 | 89 |
* @param child tells that the instance is child of another because of indentation |
84 | 90 |
* @return The string in json format representing this instance |
85 | 91 |
*/ |
Také k dispozici: Unified diff
re #7893 Constants + repeating lines + html tag pairs in comments