Rev 1929 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1848 | jmachado | 1 | package pt.estgp.estgweb.utils.documentBuilder; |
2 | |||
1929 | grupo1 | 3 | import com.owlike.genson.Genson; |
4 | import com.owlike.genson.GensonBuilder; |
||
5 | import org.json.JSONException; |
||
6 | import org.json.JSONObject; |
||
7 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.CourseReportDocument; |
||
1848 | jmachado | 8 | import pt.estgp.estgweb.utils.ClassUtils; |
9 | |||
1929 | grupo1 | 10 | import java.util.Date; |
1848 | jmachado | 11 | import java.util.List; |
12 | |||
13 | /** |
||
14 | * Created by jorgemachado on 07/11/17. |
||
15 | */ |
||
16 | public class ExtensibleDocObject |
||
17 | { |
||
1930 | grupo1 | 18 | |
19 | |||
20 | |||
1929 | grupo1 | 21 | private static Genson gensonGenericLoad; |
22 | static{ |
||
23 | gensonGenericLoad = new GensonBuilder() |
||
1930 | grupo1 | 24 | .useMethods(true) |
25 | .useFields(true) |
||
26 | .useRuntimeType(true) //para ignorar a CGLIB do courseUnitEvaluation |
||
27 | .useClassMetadata(true) |
||
28 | .useDateAsTimestamp(true) |
||
29 | .exclude(1.5.0/docs/api/java/lang/Class.html">Class.class) |
||
30 | .exclude(5+0%2Fdocs%2Fapi+Date">Date.class) |
||
31 | .exclude(java.sql.5+0%2Fdocs%2Fapi+Timestamp">Timestamp.class) |
||
32 | .exclude(java.sql.5+0%2Fdocs%2Fapi+Date">Date.class) |
||
33 | .create(); |
||
1929 | grupo1 | 34 | } |
35 | |||
36 | public static CourseReportDocument fromJson(1.5.0/docs/api/java/lang/String.html">String json) |
||
37 | { |
||
38 | return gensonGenericLoad.deserialize(json,CourseReportDocument.class); |
||
39 | } |
||
1930 | grupo1 | 40 | |
41 | |||
42 | |||
43 | /** |
||
44 | * Generic Json Object only for local class methods |
||
45 | * @return |
||
46 | * @throws JSONException |
||
47 | */ |
||
1929 | grupo1 | 48 | public JSONObject toJsonObject() throws JSONException |
49 | { |
||
50 | return new JSONObject(toJson()); |
||
51 | } |
||
1930 | grupo1 | 52 | |
53 | /** |
||
54 | * * Generic Json Object only for local class methods |
||
55 | * @return |
||
56 | * @throws java.io.IOException |
||
57 | */ |
||
1929 | grupo1 | 58 | public 1.5.0/docs/api/java/lang/String.html">String toJson() |
59 | { |
||
60 | return gensonGenericLoad.serialize(this); |
||
61 | } |
||
62 | |||
1930 | grupo1 | 63 | |
1848 | jmachado | 64 | public List<String> getAllSuperClasses() |
65 | { |
||
66 | return ClassUtils.getAllSuperClasses(this.getClass()); |
||
67 | } |
||
68 | public void setAllSuperClasses(List<String> superclasses) |
||
69 | { |
||
70 | |||
71 | } |
||
1929 | grupo1 | 72 | |
1930 | grupo1 | 73 | |
74 | } |