Rev 1857 | 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 | { |
||
1929 | grupo1 | 18 | private static Genson gensonGenericLoad; |
19 | |||
20 | static{ |
||
21 | gensonGenericLoad = new GensonBuilder() |
||
22 | .useMethods(true) |
||
23 | .useFields(true) |
||
24 | .useRuntimeType(true) //para ignorar a CGLIB do courseUnitEvaluation |
||
25 | .useClassMetadata(true) |
||
26 | .useDateAsTimestamp(true) |
||
27 | .exclude(1.5.0/docs/api/java/lang/Class.html">Class.class) |
||
28 | .exclude(5+0%2Fdocs%2Fapi+Date">Date.class) |
||
29 | .exclude(java.sql.5+0%2Fdocs%2Fapi+Timestamp">Timestamp.class) |
||
30 | .exclude(java.sql.5+0%2Fdocs%2Fapi+Date">Date.class) |
||
31 | .create(); |
||
32 | } |
||
33 | |||
34 | public static CourseReportDocument fromJson(1.5.0/docs/api/java/lang/String.html">String json) |
||
35 | { |
||
36 | return gensonGenericLoad.deserialize(json,CourseReportDocument.class); |
||
37 | } |
||
38 | /** |
||
39 | * Generic Json Object only for local class methods |
||
40 | * @return |
||
41 | * @throws JSONException |
||
42 | */ |
||
43 | public JSONObject toJsonObject() throws JSONException |
||
44 | { |
||
45 | return new JSONObject(toJson()); |
||
46 | } |
||
47 | /** |
||
48 | * * Generic Json Object only for local class methods |
||
49 | * @return |
||
50 | * @throws java.io.IOException |
||
51 | */ |
||
52 | public 1.5.0/docs/api/java/lang/String.html">String toJson() |
||
53 | { |
||
54 | return gensonGenericLoad.serialize(this); |
||
55 | } |
||
56 | |||
1848 | jmachado | 57 | public List<String> getAllSuperClasses() |
58 | { |
||
59 | return ClassUtils.getAllSuperClasses(this.getClass()); |
||
60 | } |
||
1929 | grupo1 | 61 | |
1848 | jmachado | 62 | public void setAllSuperClasses(List<String> superclasses) |
63 | { |
||
64 | |||
65 | } |
||
1929 | grupo1 | 66 | |
1848 | jmachado | 67 | } |