Subversion Repositories bacoAlunos

Rev

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

package pt.estgp.estgweb.utils.documentBuilder;

import com.owlike.genson.Genson;
import com.owlike.genson.GensonBuilder;
import org.json.JSONException;
import org.json.JSONObject;
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.CourseReportDocument;
import pt.estgp.estgweb.utils.ClassUtils;

import java.util.Date;
import java.util.List;

/**
 * Created by jorgemachado on 07/11/17.
 */

public class ExtensibleDocObject
{
    private static Genson gensonGenericLoad;

    static{
        gensonGenericLoad = new GensonBuilder()
                        .useMethods(true)
                        .useFields(true)
                        .useRuntimeType(true) //para ignorar a CGLIB do courseUnitEvaluation
                        .useClassMetadata(true)
                        .useDateAsTimestamp(true)
                        .exclude(1.5.0/docs/api/java/lang/Class.html">Class.class)
                        .exclude(5+0%2Fdocs%2Fapi+Date">Date.class)
                        .exclude(java.sql.5+0%2Fdocs%2Fapi+Timestamp">Timestamp.class)
                        .exclude(java.sql.5+0%2Fdocs%2Fapi+Date">Date.class)
                        .create();
    }

    public static CourseReportDocument fromJson(1.5.0/docs/api/java/lang/String.html">String json)
    {
        return gensonGenericLoad.deserialize(json,CourseReportDocument.class);
    }
            /**
             * Generic Json Object only for local class methods
             * @return
             * @throws JSONException
             */

    public JSONObject toJsonObject() throws JSONException
    {
        return new JSONObject(toJson());
    }
            /**
             * * Generic Json Object only for local class methods
             * @return
             * @throws java.io.IOException
             */

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

    public List<String> getAllSuperClasses()
    {
        return ClassUtils.getAllSuperClasses(this.getClass());
    }

    public void setAllSuperClasses(List<String> superclasses)
    {

    }

}