Projekt

Obecné

Profil

« Předchozí | Další » 

Revize e48f57d1

Přidáno uživatelem Jan Havlíček před asi 4 roky(ů)

#re#7832 Parent classes values OK
Parent class field names OK, indetation not so yet

Zobrazit rozdíly:

project/Deserializer/bcha.json
1 1
{
2
	class samples.ok.Simple : {
3
		"testDouble" : 1.0, 
4
		"testInt" : 123, 
5
		"intArray" : [ 5, 10, 15 ], 
6
		"locInnerClassInstance" : {
7
			class samples.ok.Inner : {
8
				"vnitrni" : "INNER STRING AM I"
9
			}
10
		}, 
11
		"localEnum" : LOW, 
12
		"pozdrav" : "AHOJ", 
13
		"stringArray" : [ "A", "B", "C" ]
14
	}
2
	class samples.ok.SimpleChild extends samples.ok.Simple : {
3
		"navic" : "AHOJ, jsem tu navic"
4
	},
5
{
6
		class samples.ok.Simple : {
7
			"testDouble" : 1.0, 
8
			"testInt" : 123, 
9
			"pozdrav" : "AHOJ"
10
		}	
11
}
15 12
}
project/Deserializer/src/Converter.java
72 72
					//replace VS parametr
73 73
					//Pustit 2X s parametrem nenabori vnitrni data (kde muzou byt html znacky)
74 74
					//Ciste HTML / Cisty JSON
75
					json += cnt.toJson("");
75
					json += cnt.toJson("", null);
76 76
				}
77 77
			}
78 78

  
project/Deserializer/src/Deserializer.java
42 42
		stage.show();
43 43
		
44 44
		//tests
45
		Converter thread = new Converter(this, new File("Deserializer/simple.out"), new File("Deserializer/bcha.json"));
45
		Converter thread = new Converter(this, new File("Deserializer/simpleChild.out"), new File("Deserializer/bcha.json"));
46 46
		thread.start();
47 47
	}
48 48
	
project/Deserializer/src/jdeserialize/arrayobj.java
1 1
package jdeserialize;
2 2

  
3
import java.util.Map;
4

  
3 5
/**
4 6
 * <p>
5 7
 * Represents an array instance, including the values the comprise the array.
......
30 32
        this.data = data;
31 33
    }
32 34

  
33
    public @Override String toJson(String indentation) {
35
    public @Override String toJson(String indentation, Map<classdesc, Map<field, Object>> fielddata) {
34 36
        StringBuilder sb = new StringBuilder();
35 37
        sb.append("[ ");
36 38

  
37 39
        for (Object el : this.data) {
38 40
            if (el != null) {
39 41
                if (el instanceof content) {
40
                    sb.append(((content) el).toJson(indentation));
42
                    sb.append(((content) el).toJson(indentation, fielddata));
41 43
                }else{
42 44
                    sb.append(el.toString());
43 45
                }
44
                // el null!
46
                
45 47
                if (!el.equals(this.data.get(this.data.size() - 1))) {
46 48
                    sb.append(", ");
47 49
                }
project/Deserializer/src/jdeserialize/classdesc.java
223 223
            }
224 224
        }
225 225
    }
226

  
227
    public @Override String toJson(String indentation, Map<classdesc, Map<field, Object>> fielddata)
228
    {
229
        StringBuffer sb = new StringBuffer();
230
        String val = "";
231
        
232
        indentation += "\t";
233

  
234
        // ClassName
235
        sb.append("{\n").append(indentation).append("class ").append(this.name);
236
        // extends
237
        if (this.superclass != null) {
238
            sb.append(" extends ").append(this.superclass.name);
239
        }
240
        // implements
241
        if (this.interfaces != null) {
242
            sb.append(" implements ");
243
            for (String str : this.interfaces) {
244
                sb.append(str);
245
            }
246
        }
247
        sb.append(" : {"); // ending of first line
248
        
249
        indentation += "\t";
250

  
251
        for (field f : this.fields) {
252
            // v this.fielddata najit element, jehoz key == classdesc
253
            // v tomto prvku fielddata najdu value (element) podle key == f
254
            // jeho value je chtena hodnota
255
            var locVal = fielddata.get(this).get(f);
256

  
257
            if(locVal instanceof content)
258
            {
259
                val = ((content)locVal).toJson(indentation, fielddata);
260
            }
261
            else {
262
                val = locVal.toString();
263
            }
264

  
265
            sb.append("\n").append(indentation);
266
            sb.append("\"").append(f.name).append("\"");
267
            sb.append(" : ");
268
            sb.append(val);
269

  
270
            if (!f.equals(this.fields[this.fields.length - 1])) {
271
                sb.append(", ");
272
            }
273
        }
274
        indentation = indentation.substring(0, indentation.length() - 1);
275

  
276
        sb.append("\n").append(indentation).append("}");
277
        
278

  
279
        if(this.superclass != null)
280
        {
281
            sb.append(",\n");
282
            sb.append(this.superclass.toJson(indentation, fielddata));
283
        }
284
        
285
        indentation = indentation.substring(0, indentation.length() - 1);
286
        sb.append(indentation).append("\n}");
287

  
288
        return sb.toString();
289
    }
226 290
}
227 291

  
project/Deserializer/src/jdeserialize/content.java
1 1
package jdeserialize;
2 2

  
3
import java.util.Map;
4

  
3 5
/**
4 6
 * <p>
5
 * Generic interface for all data that may be read from the stream (except null).  
7
 * Generic interface for all data that may be read from the stream (except
8
 * null).
6 9
 * </p>
7 10
 *
8 11
 * <p>
9
 * A successful read of the stream will result in a series of content instances or null
10
 * references.  For details on specific metadata, see documentation on implementing
11
 * classes/subinterfaces.
12
 * A successful read of the stream will result in a series of content instances
13
 * or null references. For details on specific metadata, see documentation on
14
 * implementing classes/subinterfaces.
12 15
 * </p>
13 16
 */
14 17
public interface content {
......
65 68
     */
66 69
    public void setIsExceptionObject(boolean value);
67 70

  
68
    public String toJson(String indentation);
71
    public String toJson(String indentation, Map<classdesc, Map<field, Object>> fielddata);
69 72
}
70 73

  
project/Deserializer/src/jdeserialize/contentbase.java
1 1
package jdeserialize;
2 2

  
3
import java.util.Map;
4

  
3 5
/**
4 6
 * Provides a skeleton content implementation.
5 7
 */
......
25 27
    public void validate() throws ValidityException {
26 28
    }
27 29

  
28
    public @Override String toJson(String indetation)
30
    public @Override String toJson(String indetation, Map<classdesc, Map<field, Object>> fielddata)
29 31
    {
30 32
        return this.toString();
31 33
    }
project/Deserializer/src/jdeserialize/enumobj.java
1 1
package jdeserialize;
2 2

  
3
import java.util.Map;
4

  
3 5
/**
4 6
 * <p>
5
 * Represents an enum instance.  As noted in the serialization spec, this consists of
6
 * merely the class description (represented by a classdesc) and the string corresponding
7
 * to the enum's value.  No other fields are ever serialized.
7
 * Represents an enum instance. As noted in the serialization spec, this
8
 * consists of merely the class description (represented by a classdesc) and the
9
 * string corresponding to the enum's value. No other fields are ever
10
 * serialized.
8 11
 * </p>
9 12
 */
10 13
public class enumobj extends contentbase {
......
31 34
        this.classdesc = cd;
32 35
        this.value = so;
33 36
    }
34
    public @Override String toJson(String indetation) {
37
    public @Override String toJson(String indetation, Map<classdesc, Map<field, Object>> fielddata) {
35 38
        return this.value.value;
36 39
    }
37 40

  
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)
29
    public @Override String toJson(String indentation, Map<classdesc, Map<field, Object>> fielddata)
30 30
    {
31 31
        StringBuffer sb = new StringBuffer();
32 32
        String val = "";
33 33
        
34 34
        indentation += "\t";
35 35

  
36
        /*if (classdesc.getType() == contenttype.CLASSDESC && !instance.indentedClasses.contains(classdesc.name)) {*/
37
           /* instance.indentedClasses.add(classdesc.name);
38
        }*/
39

  
40 36
        // ClassName
41 37
        sb.append("{\n").append(indentation).append("class ").append(classdesc.name);
42
        //System.out.println(sb.toString());
43 38
        // extends
44 39
        if (classdesc.superclass != null) {
45 40
            sb.append(" extends ").append(classdesc.superclass.name);
46
            //System.out.println(sb.toString());
47 41
        }
48 42
        // implements
49 43
        if (classdesc.interfaces != null) {
......
51 45
            for (String str : classdesc.interfaces) {
52 46
                sb.append(str);
53 47
            }
54
            //System.out.println(sb.toString());
55 48
        }
56 49
        sb.append(" : {"); // ending of first line
57 50
        
58 51
        indentation += "\t";
59
        //System.out.println(sb.toString());
60 52

  
61 53
        for (field f : classdesc.fields) {
62 54
            // v this.fielddata najit element, jehoz key == classdesc
63 55
            // v tomto prvku fielddata najdu value (element) podle key == f
64 56
            // jeho value je chtena hodnota
65
            
66 57
            var locVal = this.fielddata.get(classdesc).get(f);
67 58

  
68 59
            if(locVal instanceof content)
69 60
            {
70
                val = ((content)locVal).toJson(indentation);
61
                val = ((content)locVal).toJson(indentation, this.fielddata);
71 62
            }
72 63
            else {
73 64
                val = locVal.toString();
......
77 68
            sb.append("\"").append(f.name).append("\"");
78 69
            sb.append(" : ");
79 70
            sb.append(val);
80
            //System.out.println(sb.toString());
81 71

  
82 72
            if (!f.equals(classdesc.fields[classdesc.fields.length - 1])) {
83 73
                sb.append(", ");
84
                //System.out.println(sb.toString());
85 74
            }
86 75
        }
87 76
        indentation = indentation.substring(0, indentation.length() - 1);
88 77

  
89
        sb.append("\n").append(indentation).append("}\n");
90
        indentation = indentation.substring(0, indentation.length() - 1);
91
        sb.append(indentation).append("}");
92
        //System.out.println(sb.toString());
78
        sb.append("\n").append(indentation).append("}");
79
        
93 80

  
94
        /*if (classdesc.getType() == contenttype.CLASSDESC && instance.indentedClasses.contains(classdesc.name)) {*/
81
        if(classdesc.superclass != null)
82
        {
83
            sb.append(",\n");
84
            sb.append(classdesc.superclass.toJson(indentation, this.fielddata));
85
        }
95 86
        
96
            /*instance.indentedClasses.remove(classdesc.name);
97
        }*/
87
        indentation = indentation.substring(0, indentation.length() - 1);
88
        sb.append(indentation).append("\n}");
98 89

  
99 90
        return sb.toString();
100 91
    }
project/Deserializer/src/jdeserialize/stringobj.java
1 1
package jdeserialize;
2

  
2 3
import java.io.*;
4
import java.util.Map;
3 5

  
4 6
/**
5 7
 * Represents a serialized string object.  This is primarily used in serialized streams;
......
16 18
        return x;
17 19
    }
18 20

  
19
    public @Override String toJson(String indetation)
21
    public @Override String toJson(String indetation, Map<classdesc, Map<field, Object>> fielddata)
20 22
    {
21 23
        return "\"" + this.value + "\"";
22 24
    }

Také k dispozici: Unified diff