Subversion Repositories bacoAlunos

Rev

Rev 1692 | Rev 1778 | 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)
27
                .include(1.5.0/docs/api/java/lang/String.html">String.class);
28
        genson = gensonBuilder.create();
29
 
30
    }
1776 jmachado 31
    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 32
    {
33
        return genson.serialize(this);
34
    }
35
 
1776 jmachado 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 {
1692 jmachado 37
        return genson.deserialize(json, RepositoryDocumentInterfaceImpl.class);
38
    }
39
 
1776 jmachado 40
    public JSONObject toJsonObject() throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException {
1692 jmachado 41
        return new JSONObject(toJson());
42
    }
43
 
1776 jmachado 44
    public static JSONArray toJsonArray(List<RepositoryDocumentInterfaceImpl> collections) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException {
1692 jmachado 45
        return new JSONArray(genson.serialize(collections));
46
    }
47
 
48
}