Example usage for com.google.gson GsonBuilder setDateFormat

List of usage examples for com.google.gson GsonBuilder setDateFormat

Introduction

In this page you can find the example usage for com.google.gson GsonBuilder setDateFormat.

Prototype

public GsonBuilder setDateFormat(int style) 

Source Link

Document

Configures Gson to to serialize Date objects according to the style value provided.

Usage

From source file:net.daw.service.generic.implementation.ViewServiceGenImpl.java

License:Open Source License

@Override
public String get(Integer id) throws Exception {
    String data = null;/*w  w w.  ja  v a  2s .c o  m*/
    try {
        oConnection.setAutoCommit(false);
        BeanGenImpl oGenericBean = (BeanGenImpl) Class
                .forName("net.daw.bean.generic.specific.implementation." + strPojo + "BeanGenSpImpl")
                .newInstance();
        Constructor c = Class.forName("net.daw.dao.generic.specific.implementation." + strPojo + "DaoGenSpImpl")
                .getConstructor(String.class, Connection.class);
        TableDaoGenImpl oGenericDao = (TableDaoGenImpl) c.newInstance(strObjectName, oConnection);
        oGenericBean.setId(id);
        oGenericBean = (BeanGenImpl) (BeanInterface) oGenericDao.get(oGenericBean,
                AppConfigurationHelper.getJsonDepth());
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setDateFormat("dd/MM/yyyy");
        Gson gson = gsonBuilder.excludeFieldsWithoutExposeAnnotation().create();
        data = gson.toJson(oGenericBean);
    } catch (Exception ex) {
        oConnection.rollback();
        ExceptionBooster.boost(new Exception(this.getClass().getName() + ":get ERROR: " + ex.getMessage()));
    } finally {
        oConnection.commit();
    }
    return data;
}

From source file:net.daw.service.generic.implementation.ViewServiceGenImpl.java

License:Open Source License

@Override
public String getPage(int intRegsPerPag, int intPage, ArrayList<FilterBeanHelper> alFilter,
        HashMap<String, String> hmOrder) throws Exception {
    String data = null;/* w w  w. ja  v a2 s.  co m*/
    try {
        oConnection.setAutoCommit(false);
        BeanGenImpl oGenericBean = (BeanGenImpl) Class
                .forName("net.daw.bean.generic.specific.implementation." + strPojo + "BeanGenSpImpl")
                .newInstance();
        Constructor c = Class.forName("net.daw.dao.generic.specific.implementation." + strPojo + "DaoGenSpImpl")
                .getConstructor(String.class, Connection.class);
        TableDaoGenImpl oGenericDao = (TableDaoGenImpl) c.newInstance(strObjectName, oConnection);
        List<BeanInterface> loGenericBean = oGenericDao.getPage(intRegsPerPag, intPage, alFilter, hmOrder);
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setDateFormat("dd/MM/yyyy");
        Gson gson = gsonBuilder.excludeFieldsWithoutExposeAnnotation().create();
        data = gson.toJson(loGenericBean);
        data = "{\"list\":" + data + "}";
    } catch (Exception ex) {
        oConnection.rollback();
        ExceptionBooster.boost(new Exception(this.getClass().getName() + ":getPage ERROR: " + ex.getMessage()));
    } finally {
        oConnection.commit();
    }
    return data;
}

From source file:net.daw.service.generic.specific.implementation.AsignaturaServiceGenSpImpl.java

License:Open Source License

public String getPageAsignaturaFiltrada(Integer id_usuario, int intRegsPerPag, int intPage,
        ArrayList<FilterBeanHelper> hmFilter, HashMap<String, String> hmOrder) throws Exception {
    String data = null;/*from w  w  w.j av a 2s  .  c o m*/
    try {
        oConnection.setAutoCommit(false);
        AsignaturaDaoGenSpImpl oAsignaturaDAO = new AsignaturaDaoGenSpImpl(strObjectName, oConnection);
        List<AsignaturaBeanGenSpImpl> oAsignaturas = oAsignaturaDAO.getPageAsignaturaFiltrada(id_usuario,
                intRegsPerPag, intPage, hmFilter, hmOrder);
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setDateFormat("dd/MM/yyyy");
        Gson gson = gsonBuilder.create();
        data = gson.toJson(oAsignaturas);
        data = "{\"list\":" + data + "}";
        oConnection.commit();
    } catch (Exception ex) {
        oConnection.rollback();
        ExceptionBooster.boost(new Exception(this.getClass().getName() + ":getPage ERROR: " + ex.getMessage()));
    }
    return data;

}

From source file:net.daw.service.generic.specific.implementation.TareaServiceGenSpImpl.java

License:Open Source License

@Override
public String get(Integer id) throws Exception {
    String data = null;/*from w  w w  .j  a v a 2 s  .  c  o m*/
    try {
        oConnection.setAutoCommit(false);
        TareaDaoGenSpImpl oTareaDAO = new TareaDaoGenSpImpl(strObjectName, oConnection);
        TareaBeanGenSpImpl oTarea = new TareaBeanGenSpImpl(id);
        oTarea = oTareaDAO.get(oTarea, AppConfigurationHelper.getJsonDepth());
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setDateFormat("dd/MM/yyyy HH:mm:ss");
        Gson gson = gsonBuilder.create();
        data = gson.toJson(oTarea);
        oConnection.commit();
    } catch (Exception ex) {
        oConnection.rollback();
        ExceptionBooster.boost(new Exception(this.getClass().getName() + ":get ERROR: " + ex.getMessage()));
    }
    return data;
}

From source file:net.daw.service.generic.specific.implementation.TareaServiceGenSpImpl.java

License:Open Source License

@Override
public String getPage(int intRegsPerPag, int intPage, ArrayList<FilterBeanHelper> alFilter,
        HashMap<String, String> hmOrder) throws Exception {
    String data = null;/*from   w w w. jav  a 2 s .co  m*/
    try {
        oConnection.setAutoCommit(false);
        TareaDaoGenSpImpl oTareaDAO = new TareaDaoGenSpImpl(strObjectName, oConnection);
        List<TareaBeanGenSpImpl> oTareas = oTareaDAO.getPage(intRegsPerPag, intPage, alFilter, hmOrder);
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setDateFormat("dd/MM/yyyy HH:mm:ss");
        Gson gson = gsonBuilder.create();
        data = gson.toJson(oTareas);
        data = "{\"list\":" + data + "}";
        oConnection.commit();
    } catch (Exception ex) {
        oConnection.rollback();
        ExceptionBooster.boost(new Exception(this.getClass().getName() + ":getPage ERROR: " + ex.getMessage()));
    }
    return data;
}

From source file:net.daw.service.specific.implementation.ActividadServiceSpImpl.java

License:Open Source License

@Override
public String get(Integer id) throws Exception {
    String data = null;/* ww w  .  ja  v  a2 s .c om*/
    try {
        oConnection.setAutoCommit(false);
        ActividadDaoSpcImpl oActividadDAO = new ActividadDaoSpcImpl(strObjectName, oConnection);
        ActividadBeanGenSpImpl oActividad = new ActividadBeanGenSpImpl(id);
        oActividad = oActividadDAO.get(oActividad, 1);
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setDateFormat("dd/MM/yyyy");
        Gson gson = gsonBuilder.create();
        data = gson.toJson(oActividad);
        oConnection.commit();
    } catch (Exception ex) {
        oConnection.rollback();
        ExceptionBooster.boost(new Exception(this.getClass().getName() + ":get ERROR: " + ex.getMessage()));
    }
    return data;
}

From source file:net.daw.service.specific.implementation.ActividadServiceSpImpl.java

License:Open Source License

@Override
public String getPage(int intRegsPerPag, int intPage, ArrayList<FilterBeanHelper> alFilter,
        HashMap<String, String> hmOrder) throws Exception {
    String data = null;//from   www  . j av a 2s  . c  o  m
    try {
        oConnection.setAutoCommit(false);
        ActividadDaoSpcImpl oActividadDAO = new ActividadDaoSpcImpl(strObjectName, oConnection);
        List<ActividadBeanGenSpImpl> oActividads = oActividadDAO.getPage(intRegsPerPag, intPage, alFilter,
                hmOrder);
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setDateFormat("dd/MM/yyyy");
        Gson gson = gsonBuilder.create();
        data = gson.toJson(oActividads);
        data = "{\"list\":" + data + "}";
        oConnection.commit();
    } catch (Exception ex) {
        oConnection.rollback();
        ExceptionBooster.boost(new Exception(this.getClass().getName() + ":getPage ERROR: " + ex.getMessage()));
    }
    return data;
}

From source file:net.daw.service.specific.implementation.BlogService.java

License:MIT License

public String get() throws Exception {

    Connection oConnection = new BoneConnectionPoolImpl().newConnection();
    UsuarioBean oUserBean = (UsuarioBean) oRequest.getSession().getAttribute("userBean");
    int id_usuario = oUserBean.getId();
    BlogDao oBlogDao = new BlogDao(oConnection);

    int id = ParameterCook.prepareId(oRequest);

    DocumentoBean oDocumentoBean = new DocumentoBean();
    oDocumentoBean.setId(id);// www  .  j a  v  a2 s.  co m
    ArrayList<BlogBean> alBlogBean = new ArrayList();
    alBlogBean = oBlogDao.getBlog(oDocumentoBean, id_usuario);

    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setDateFormat("dd/MM/yyyy");
    Gson gson = gsonBuilder.create();
    String data = "{\"status\":200,\"message\":" + gson.toJson(alBlogBean) + "}";

    return data;

}

From source file:net.daw.service.specific.implementation.BlogService.java

License:MIT License

public String getall() throws Exception {

    Connection oConnection = new BoneConnectionPoolImpl().newConnection();
    BlogDao oBlogDao = new BlogDao(oConnection);

    UsuarioBean oUserBean = (UsuarioBean) oRequest.getSession().getAttribute("userBean");
    int id_usuario = oUserBean.getId();

    int id = ParameterCook.prepareId(oRequest);

    DocumentoBean oDocumentoBean = new DocumentoBean();
    oDocumentoBean.setId(id);//from w ww.j a  v  a2s . c  om
    oDocumentoBean.setId_usuario(id_usuario);
    ArrayList<DocumentoBean> alBlogBean = new ArrayList();
    alBlogBean = oBlogDao.getall(oDocumentoBean);

    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setDateFormat("dd/MM/yyyy");
    Gson gson = gsonBuilder.create();
    String data = "{\"status\":200,\"message\":" + gson.toJson(alBlogBean) + "}";

    return data;

}

From source file:net.daw.service.specific.implementation.ClienteServiceSpImpl.java

License:Open Source License

@Override
public String get(Integer id) throws Exception {
    String data = null;//from  w  w  w .  ja v  a 2  s. c  om
    try {
        oConnection.setAutoCommit(false);
        ClienteDaoSpcImpl oClienteDAO = new ClienteDaoSpcImpl(strObjectName, oConnection);
        ClienteBeanGenSpImpl oCliente = new ClienteBeanGenSpImpl(id);
        oCliente = oClienteDAO.get(oCliente, AppConfigurationHelper.getJsonDepth());
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setDateFormat("dd/MM/yyyy");
        Gson gson = gsonBuilder.create();
        data = gson.toJson(oCliente);
        oConnection.commit();
    } catch (Exception ex) {
        oConnection.rollback();
        ExceptionBooster.boost(new Exception(this.getClass().getName() + ":get ERROR: " + ex.getMessage()));
    }
    return data;
}