Skip to content

Commit

Permalink
0.8 ->corrige almacenar y recuperar fechas <-
Browse files Browse the repository at this point in the history
  • Loading branch information
avbravo committed Dec 19, 2016
1 parent 81618a2 commit 8505f15
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 27 deletions.
2 changes: 1 addition & 1 deletion jgmongo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.jgmongo</groupId>
<artifactId>jgmongo</artifactId>
<version>0.7.3</version>
<version>0.8</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/
package com.jgmongo.interfaces;



import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.jgmongo.util.DateDeserializer;
Expand All @@ -23,8 +21,6 @@
*/
public interface ServicesInterfaces<T> {



default public Document toDoc(T t) {
Document doc = new Document();
try {
Expand All @@ -33,18 +29,20 @@ default public Document toDoc(T t) {
System.out.println("toDocument() " + e.getLocalizedMessage());
}
return doc;
}
default T toJava(Document doc,T t1) {
T o=fromJsontoJava(doc.toJson(), (Class<T>) t1);
}

default T toJava(Document doc, T t1) {

T o = fromJsontoJava(doc.toJson(), (Class<T>) t1);

return o;
}

default <T> T fromJsontoJava(String json, Class<T> clazz) {
T jsonToObject = getGson().fromJson(json, clazz);
return jsonToObject;
}

/**
* devuelve el json como un string
*
Expand Down Expand Up @@ -73,7 +71,6 @@ default String jsonToString(String url, String apikey) {
*
* @return
*/

// default Gson getGson() {
//
// Gson gson = new GsonBuilder()
Expand All @@ -83,31 +80,64 @@ default String jsonToString(String url, String apikey) {
//
// return gson;
// }
/**
* formato de fecha
*
* @param dateformat
* @return
*/
default Gson getGson(String... dateformat) {
String format = "dd/MM/yyyy HH:mm:ss a";
if (dateformat.length != 0) {
format = dateformat[0];

default Gson getGson() {

}
Gson gson = new GsonBuilder()
.registerTypeAdapter(Date.class, new DateDeserializer())
.setDateFormat("dd/MM/yyyy HH:mm:ss a")
.setPrettyPrinting()

.create();

return gson;
}
default Gson getGsonDate() {

// default Gson getGson() {
//
// Gson gson = new GsonBuilder()
// .setDateFormat("dd/MM/yyyy HH:mm:ss a")
// .setPrettyPrinting()
//
// .create();
//
// return gson;
// }
default Gson getGsonFecha() {

Gson gson = new GsonBuilder()
.registerTypeAdapter(Date.class, new DateDeserializer())
.setDateFormat("dd/MM/yyyy")
.setPrettyPrinting()

.create();

return gson;
}





// default Gson getGson() {
//
// Gson gson = new GsonBuilder()
// .registerTypeAdapter(Date.class, new DateDeserializer())
// .setPrettyPrinting()
//
// .create();
//
// return gson;
// }
// default Gson getGsonDate() {
//
// Gson gson = new GsonBuilder()
// .registerTypeAdapter(Date.class, new DateDeserializer())
// .setPrettyPrinting()
// .create();
//
// return gson;
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public <T> T fromJsontoPojo(String json, Class<T> clazz) {
* @param clazz
* @return
*/
public <T> T fromJsontoPojoDate(String json, Class<T> clazz) {
T jsonToObject = getGsonDate().fromJson(json, clazz);
return jsonToObject;
}
// public <T> T fromJsontoPojoDate(String json, Class<T> clazz) {
// T jsonToObject = getGsonDate().fromJson(json, clazz);
// return jsonToObject;
// }



Expand Down

0 comments on commit 8505f15

Please sign in to comment.