Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 446aa6fb

Přidáno uživatelem Michal Horký před asi 4 roky(ů)

re #7879

Soubory Converter.java a instance.java změněny.

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/Deserializer.java
159 159
		});
160 160
		
161 161
		//tests
162
		Converter thread = new Converter(this, new File("Deserializer/simple.out"), new File("Deserializer/bcha.json"));
162
		Converter thread = new Converter(this, new File("Deserializer/simpleChild.out"), new File("Deserializer/bcha.json"));
163 163
		thread.start();
164 164
	}
165 165
	
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/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