Rev 1776 | Go to most recent revision | Details | 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; |
||
4 | import com.owlike.genson.TransformationException; |
||
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 { |
||
25 | Genson.Builder gensonBuilder = new Genson.Builder() |
||
26 | .exclude(5+0%2Fdocs%2Fapi+Object">Object.class) |
||
27 | .include(1.5.0/docs/api/java/lang/String.html">String.class); |
||
28 | genson = gensonBuilder.create(); |
||
29 | |||
30 | } |
||
31 | public 1.5.0/docs/api/java/lang/String.html">String toJson() throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException |
||
32 | { |
||
33 | return genson.serialize(this); |
||
34 | } |
||
35 | |||
36 | 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, TransformationException { |
||
37 | return genson.deserialize(json, RepositoryDocumentInterfaceImpl.class); |
||
38 | } |
||
39 | |||
40 | public JSONObject toJsonObject() throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException { |
||
41 | return new JSONObject(toJson()); |
||
42 | } |
||
43 | |||
44 | public static JSONArray toJsonArray(List<RepositoryDocumentInterfaceImpl> collections) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException { |
||
45 | return new JSONArray(genson.serialize(collections)); |
||
46 | } |
||
47 | |||
48 | } |