Rev 1776 | Rev 1780 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1692 | jmachado | 1 | package pt.estgp.estgweb.domain; |
2 | |||
3 | import com.owlike.genson.Genson; |
||
1776 | jmachado | 4 | import com.owlike.genson.GensonBuilder; |
1692 | jmachado | 5 | import org.json.JSONArray; |
6 | import org.json.JSONException; |
||
7 | import org.json.JSONObject; |
||
8 | |||
9 | import java.io.IOException; |
||
10 | import java.io.Serializable; |
||
11 | import java.util.List; |
||
12 | |||
13 | /** |
||
14 | * Created by jorgemachado on 27/03/17. |
||
15 | */ |
||
16 | public class RepositoryDocumentInterfaceImpl extends RepositoryDocumentInterface { |
||
17 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
18 | public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable() { |
||
19 | return getId(); |
||
20 | } |
||
21 | |||
22 | static Genson genson; |
||
23 | |||
24 | static { |
||
1776 | jmachado | 25 | GensonBuilder gensonBuilder = new Genson.Builder() |
1692 | jmachado | 26 | .exclude(5+0%2Fdocs%2Fapi+Object">Object.class) |
1778 | jmachado | 27 | .include(1.5.0/docs/api/java/lang/Boolean.html">Boolean.class) |
28 | .include(1.5.0/docs/api/java/lang/Integer.html">Integer.class) |
||
29 | .include(1.5.0/docs/api/java/lang/Long.html">Long.class) |
||
30 | .include(1.5.0/docs/api/java/lang/Double.html">Double.class) |
||
31 | .include(1.5.0/docs/api/java/lang/Float.html">Float.class) |
||
1692 | jmachado | 32 | .include(1.5.0/docs/api/java/lang/String.html">String.class); |
33 | genson = gensonBuilder.create(); |
||
34 | |||
35 | } |
||
1776 | jmachado | 36 | public 1.5.0/docs/api/java/lang/String.html">String toJson() throws 1.5.0/docs/api/java/io/IOException.html">IOException |
1692 | jmachado | 37 | { |
38 | return genson.serialize(this); |
||
39 | } |
||
40 | |||
1776 | jmachado | 41 | public static RepositoryDocumentInterfaceImpl loadFromJson(1.5.0/docs/api/java/lang/String.html">String json) throws 1.5.0/docs/api/java/io/IOException.html">IOException { |
1692 | jmachado | 42 | return genson.deserialize(json, RepositoryDocumentInterfaceImpl.class); |
43 | } |
||
44 | |||
1776 | jmachado | 45 | public JSONObject toJsonObject() throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException { |
1692 | jmachado | 46 | return new JSONObject(toJson()); |
47 | } |
||
48 | |||
1776 | jmachado | 49 | public static JSONArray toJsonArray(List<RepositoryDocumentInterfaceImpl> collections) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException { |
1692 | jmachado | 50 | return new JSONArray(genson.serialize(collections)); |
51 | } |
||
52 | |||
53 | } |