Revize 53fe2660
Přidáno uživatelem Jan Havlíček před více než 4 roky(ů)
demo_jh/Deserializer_tests/src/app/App.java | ||
---|---|---|
8 | 8 |
import java.io.ObjectOutputStream; |
9 | 9 |
import java.util.ArrayList; |
10 | 10 |
import java.util.List; |
11 |
import jdeserialize.Getopt; |
|
12 |
import jdeserialize.classdesc; |
|
13 |
import jdeserialize.content; |
|
14 |
import jdeserialize.instance; |
|
15 |
import jdeserialize.jdeserialize; |
|
11 |
import org.codehaus.jackson.map.ObjectMapper; |
|
12 |
import org.codehaus.jackson.map.ObjectWriter; |
|
13 |
import org.unsynchronized.jdeserialize; |
|
16 | 14 |
|
17 | 15 |
public class App { |
18 | 16 |
|
19 | 17 |
/** |
20 | 18 |
* When the Serialized and deserialized classes are same, but placed in diff packages, the |
21 | 19 |
* deserialization does not work. When they are |
22 |
* |
|
23 |
* !CAREFUL! For testing purposes the somehow standartized package path (org.blah.etc...) |
|
24 |
* is not followed. Repair in the future - because of used libs. |
|
25 |
* |
|
26 |
* jdeserializer also as .jar module! |
|
27 | 20 |
**/ |
28 | 21 |
public static void main(String[] args) throws Exception { |
29 | 22 |
App app = new App(); |
... | ... | |
35 | 28 |
//app.jdCallMain(); |
36 | 29 |
|
37 | 30 |
// test directly through code call |
38 |
app.jdCallLib("serialized/simple.out"); |
|
31 |
app.jdCallLib("serialized/simple.out", true, "deserializedResults/simple.json"); |
|
32 |
System.out.println("Vše OK, díky."); |
|
39 | 33 |
} |
40 | 34 |
|
41 | 35 |
/** |
... | ... | |
43 | 37 |
* |
44 | 38 |
* SHOULD NOT BE HERE |
45 | 39 |
* **/ |
46 |
private void jdCallLib(String filename) |
|
40 |
private void jdCallLib(String filename, boolean dump, String outputFileJSON)
|
|
47 | 41 |
{ |
48 | 42 |
try |
49 | 43 |
{ |
... | ... | |
64 | 58 |
//testing with only first of the contents |
65 | 59 |
String json = objectToJSON(cntnts.get(0)); |
66 | 60 |
|
61 |
if(dump) |
|
62 |
{ |
|
63 |
System.out.println(json); |
|
64 |
} |
|
65 |
if(outputFileJSON != null && !outputFileJSON.isEmpty()) |
|
66 |
{ |
|
67 |
File toWrite = new File(outputFileJSON); |
|
68 |
toWrite.createNewFile(); |
|
69 |
|
|
70 |
FileOutputStream fos = new FileOutputStream(toWrite, false); |
|
71 |
ObjectOutputStream oos = new ObjectOutputStream(fos); |
|
72 |
|
|
73 |
oos.writeObject(json); |
|
74 |
oos.flush(); |
|
75 |
oos.close(); |
|
76 |
System.out.println("Soubor " + outputFileJSON + " s deserializovaným objektem vytvořen."); |
|
77 |
} |
|
67 | 78 |
|
68 |
int c = 0; |
|
69 | 79 |
} |
70 | 80 |
catch (IOException e) |
71 | 81 |
{ |
... | ... | |
81 | 91 |
private String objectToJSON(Object in) |
82 | 92 |
{ |
83 | 93 |
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); |
84 |
String json = ow.writeValueAsString(in); |
|
94 |
String json = ""; |
|
95 |
try |
|
96 |
{ |
|
97 |
json = ow.writeValueAsString(in); |
|
98 |
} |
|
99 |
catch (IOException e) |
|
100 |
{ |
|
101 |
// TODO Auto-generated catch block |
|
102 |
e.printStackTrace(); |
|
103 |
} |
|
85 | 104 |
|
86 | 105 |
return json; |
87 | 106 |
} |
Také k dispozici: Unified diff
#7768 WORKING
Deleted not-needed project, export to JSON working,
dev comments for testing written, structure not optimized