Subversion Repositories bacoAlunos

Rev

Rev 1778 | 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.TransformationException;
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 {
        Genson.Builder gensonBuilder =  new Genson.Builder()
                .exclude(5+0%2Fdocs%2Fapi+Object">Object.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, TransformationException
    {
        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, TransformationException {
        return genson.deserialize(json, RepositoryDocumentInterfaceImpl.class);
    }

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

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

}