Subversion Repositories bacoAlunos

Rev

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

package pt.estgp.estgweb.services.courses.xsd;

import com.owlike.genson.Genson;
import com.owlike.genson.TransformationException;
import org.json.JSONException;
import org.json.JSONObject;
import pt.estgp.estgweb.utils.DynamicArrayList;

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

/**
 * Created by jorgemachado on 15/09/16.
 */

public class CursoImpl extends Curso
{
    public List<Semestre> getSemestre()
    {
        if (semestre == null) {
            semestre = new DynamicArrayList<Semestre>(SemestreImpl.class);
        }
        return this.semestre;
    }

    //ESTE GENSON e apenas para propositos de interface. O JSON gerado para envio pelas API's e feito no servico
    //CourseService.savePlanoEstudosEditado que usa o Genson obtido em CourseService.getGensonPlanoEstudos

    static Genson genson;

    static {
        Genson.Builder gensonBuilder =  new Genson.Builder()
                .exclude(5+0%2Fdocs%2Fapi+Object">Object.class)
                .include(Curso.class)
                .include(UnidadeType.class)
                .include(Semestre.Perfil.class)
                .include(Semestre.class)
                .include(UnidadeType.HorasContacto.class)
                .include(1.5.0/docs/api/java/lang/String.html">String.class)
                .include(1.5.0/docs/api/java/lang/Integer.html">Integer.class)
                .include(5+0%2Fdocs%2Fapi+List">List.class);


        genson = gensonBuilder.create();

    }

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

    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 CursoImpl 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, CursoImpl.class);
    }

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


}