Revize b8fb2f0d
Přidáno uživatelem Jan Havlíček před asi 5 roky(ů)
demo_jh/Deserializer_tests/src/SampleClasses/Simple.java | ||
---|---|---|
1 |
package SampleClasses; |
|
2 |
|
|
3 |
import java.io.Serializable; |
|
4 |
|
|
5 |
public class Simple implements Serializable |
|
6 |
{ |
|
7 |
private static final long serialVersionUID = 1L; |
|
8 |
|
|
9 |
private String pozdrav = "AHOJ"; |
|
10 |
private int testInt = 123; |
|
11 |
private double testDouble = 1.00; |
|
12 |
|
|
13 |
public Simple() |
|
14 |
{ |
|
15 |
int locInt = 5; |
|
16 |
} |
|
17 |
} |
demo_jh/Deserializer_tests/src/SampleClassesNOK/Simple.java | ||
---|---|---|
1 |
package SampleClassesNOK; |
|
2 |
|
|
3 |
import java.io.Serializable; |
|
4 |
|
|
5 |
public class Simple implements Serializable |
|
6 |
{ |
|
7 |
private static final long serialVersionUID = 1L; |
|
8 |
|
|
9 |
private String pozdrav = "AHOJ"; |
|
10 |
private int testInt = 123; |
|
11 |
private double testDouble = 1.00; |
|
12 |
|
|
13 |
public Simple() |
|
14 |
{ |
|
15 |
int locInt = 5; |
|
16 |
} |
|
17 |
} |
demo_jh/Deserializer_tests/src/SampleClassesOK/Simple.java | ||
---|---|---|
1 |
package SampleClassesOK; |
|
2 |
|
|
3 |
import java.io.Serializable; |
|
4 |
|
|
5 |
public class Simple implements Serializable |
|
6 |
{ |
|
7 |
private static final long serialVersionUID = 1L; |
|
8 |
|
|
9 |
private String pozdrav = "AHOJ"; |
|
10 |
private int testInt = 123; |
|
11 |
private double testDouble = 1.00; |
|
12 |
|
|
13 |
public Simple() |
|
14 |
{ |
|
15 |
int locInt = 5; |
|
16 |
} |
|
17 |
} |
demo_jh/Deserializer_tests/src/app/App.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
public class App |
11 | 11 |
{ |
12 |
|
|
13 |
/** |
|
14 |
* When the Serialized and deserialized classes are same, but placed in diff |
|
15 |
* packages, the deserialization does not work. |
|
16 |
* When they are |
|
17 |
* **/ |
|
12 | 18 |
public static void main(String[] args) throws Exception |
13 | 19 |
{ |
14 |
System.out.println("Starting..."); |
|
20 |
try{ |
|
21 |
System.out.println("Starting..."); |
|
15 | 22 |
|
16 |
App thisApp = new App(); |
|
17 |
thisApp.Serialize(new SampleClasses.Simple(), "serialized/simple.out"); |
|
18 |
SampleClasses.Simple test1 = thisApp.Deserialize("serialized/simple.out"); |
|
23 |
App thisApp = new App(); |
|
24 |
//thisApp.Serialize(new SampleClassesOK.Simple(), "serialized/simple.out"); |
|
25 |
|
|
26 |
SampleClassesOK.Simple test1 = thisApp.Deserialize("serialized/simple.out"); |
|
27 |
|
|
28 |
}catch(Exception e) |
|
29 |
{ |
|
30 |
System.out.println(e.toString()); |
|
31 |
System.out.println(e.getMessage()); |
|
32 |
} |
|
19 | 33 |
} |
20 | 34 |
|
21 | 35 |
private <T> T Deserialize(String inputFilePath) |
Také k dispozici: Unified diff
Some of the tests rewritten into readable code.