Rev 1771 | Rev 1778 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1505 | jmachado | 1 | package pt.estgp.estgweb.services.courses.xsd; |
2 | |||
1771 | jmachado | 3 | import com.owlike.genson.Genson; |
1776 | jmachado | 4 | import com.owlike.genson.GensonBuilder; |
1771 | jmachado | 5 | import org.json.JSONException; |
6 | import org.json.JSONObject; |
||
1505 | jmachado | 7 | import pt.estgp.estgweb.utils.DynamicArrayList; |
8 | |||
1771 | jmachado | 9 | import java.io.IOException; |
1505 | jmachado | 10 | import java.util.List; |
11 | |||
12 | /** |
||
13 | * Created by jorgemachado on 15/09/16. |
||
14 | */ |
||
15 | public class CursoImpl extends Curso |
||
16 | { |
||
1771 | jmachado | 17 | public List<Semestre> getSemestre() |
18 | { |
||
1505 | jmachado | 19 | if (semestre == null) { |
20 | semestre = new DynamicArrayList<Semestre>(SemestreImpl.class); |
||
21 | } |
||
22 | return this.semestre; |
||
1771 | jmachado | 23 | } |
1505 | jmachado | 24 | |
1771 | jmachado | 25 | //ESTE GENSON e apenas para propositos de interface. O JSON gerado para envio pelas API's e feito no servico |
26 | //CourseService.savePlanoEstudosEditado que usa o Genson obtido em CourseService.getGensonPlanoEstudos |
||
27 | |||
28 | static Genson genson; |
||
29 | |||
30 | static { |
||
1776 | jmachado | 31 | GensonBuilder gensonBuilder = new Genson.Builder() |
1771 | jmachado | 32 | .exclude(5+0%2Fdocs%2Fapi+Object">Object.class) |
33 | .include(Curso.class) |
||
34 | .include(UnidadeType.class) |
||
35 | .include(Semestre.Perfil.class) |
||
36 | .include(Semestre.class) |
||
37 | .include(UnidadeType.HorasContacto.class) |
||
38 | .include(1.5.0/docs/api/java/lang/String.html">String.class) |
||
39 | .include(1.5.0/docs/api/java/lang/Integer.html">Integer.class) |
||
40 | .include(5+0%2Fdocs%2Fapi+List">List.class); |
||
41 | |||
42 | |||
43 | genson = gensonBuilder.create(); |
||
44 | |||
1505 | jmachado | 45 | } |
46 | |||
1776 | jmachado | 47 | public static 1.5.0/docs/api/java/lang/String.html">String toJson(Curso c) throws 1.5.0/docs/api/java/io/IOException.html">IOException |
1771 | jmachado | 48 | { |
49 | return genson.serialize(c); |
||
50 | } |
||
1505 | jmachado | 51 | |
1776 | jmachado | 52 | public 1.5.0/docs/api/java/lang/String.html">String toJson() throws 1.5.0/docs/api/java/io/IOException.html">IOException |
1771 | jmachado | 53 | { |
54 | return genson.serialize(this); |
||
55 | } |
||
56 | |||
1776 | jmachado | 57 | public static CursoImpl loadFromJson(1.5.0/docs/api/java/lang/String.html">String json) throws 1.5.0/docs/api/java/io/IOException.html">IOException { |
1771 | jmachado | 58 | return genson.deserialize(json, CursoImpl.class); |
59 | } |
||
60 | |||
1776 | jmachado | 61 | public JSONObject toJsonObject() throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException { |
1771 | jmachado | 62 | return new JSONObject(toJson()); |
63 | } |
||
64 | |||
65 | |||
1505 | jmachado | 66 | } |