Subversion Repositories bacoAlunos

Rev

Rev 1776 | Rev 1780 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package pt.estgp.estgweb.domain;

import com.owlike.genson.Genson;
import com.owlike.genson.GensonBuilder;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.Serializable;
import java.util.List;

/**
 * Created by jorgemachado on 27/03/17.
 */

public class RepositoryDocumentInterfaceImpl extends RepositoryDocumentInterface {
    @1.5.0/docs/api/java/lang/Override.html">Override
    public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable() {
        return getId();
    }

    static Genson genson;

    static {
        GensonBuilder gensonBuilder =  new Genson.Builder()
                .exclude(5+0%2Fdocs%2Fapi+Object">Object.class)
                .include(1.5.0/docs/api/java/lang/Boolean.html">Boolean.class)
                .include(1.5.0/docs/api/java/lang/Integer.html">Integer.class)
                .include(1.5.0/docs/api/java/lang/Long.html">Long.class)
                .include(1.5.0/docs/api/java/lang/Double.html">Double.class)
                .include(1.5.0/docs/api/java/lang/Float.html">Float.class)
                .include(1.5.0/docs/api/java/lang/String.html">String.class);
        genson = gensonBuilder.create();

    }
    public 1.5.0/docs/api/java/lang/String.html">String toJson() throws 1.5.0/docs/api/java/io/IOException.html">IOException
    {
        return genson.serialize(this);
    }

    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 {
        return genson.deserialize(json, RepositoryDocumentInterfaceImpl.class);
    }

    public JSONObject toJsonObject() throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException {
        return new JSONObject(toJson());
    }

    public static JSONArray toJsonArray(List<RepositoryDocumentInterfaceImpl> collections) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException {
        return new JSONArray(genson.serialize(collections));
    }

}