Subversion Repositories bacoAlunos

Rev

Rev 1782 | 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;
1782 jmachado 11
import java.util.ArrayList;
1692 jmachado 12
import java.util.List;
1782 jmachado 13
import java.util.Set;
1692 jmachado 14
 
15
/**
16
 * Created by jorgemachado on 27/03/17.
17
 */
18
public class RepositoryDocumentInterfaceImpl extends RepositoryDocumentInterface {
19
    @1.5.0/docs/api/java/lang/Override.html">Override
20
    public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable() {
21
        return getId();
22
    }
23
 
24
    static Genson genson;
25
 
26
    static {
1827 jmachado 27
        GensonBuilder gensonBuilder =  new GensonBuilder()
1692 jmachado 28
                .exclude(5+0%2Fdocs%2Fapi+Object">Object.class)
1778 jmachado 29
                .include(1.5.0/docs/api/java/lang/Boolean.html">Boolean.class)
30
                .include(1.5.0/docs/api/java/lang/Integer.html">Integer.class)
31
                .include(1.5.0/docs/api/java/lang/Long.html">Long.class)
32
                .include(1.5.0/docs/api/java/lang/Double.html">Double.class)
33
                .include(1.5.0/docs/api/java/lang/Float.html">Float.class)
1782 jmachado 34
                .include(1.5.0/docs/api/java/lang/String.html">String.class)
35
                .include(1.5.0/docs/api/java/util/ArrayList.html">ArrayList.class)
36
                .include(1.5.0/docs/api/java/util/Set.html">Set.class)
37
                .include(5+0%2Fdocs%2Fapi+List">List.class);
1692 jmachado 38
        genson = gensonBuilder.create();
39
 
40
    }
1780 jmachado 41
    public 1.5.0/docs/api/java/lang/String.html">String toJson(){
1692 jmachado 42
        return genson.serialize(this);
43
    }
44
 
1776 jmachado 45
    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 46
        return genson.deserialize(json, RepositoryDocumentInterfaceImpl.class);
47
    }
48
 
1780 jmachado 49
    public JSONObject toJsonObject() throws JSONException {
1692 jmachado 50
        return new JSONObject(toJson());
51
    }
52
 
1776 jmachado 53
    public static JSONArray toJsonArray(List<RepositoryDocumentInterfaceImpl> collections) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException {
1692 jmachado 54
        return new JSONArray(genson.serialize(collections));
55
    }
56
 
57
}