Subversion Repositories bacoAlunos

Rev

Rev 1782 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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