branch develop updated (0fcf540 -> 88e7990)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository observe. See http://git.codelutin.com/observe.git from 0fcf540 Renommage services de consolidation new 88e7990 Ajout d'un adapter Gson pour les Class The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 88e7990863c7a06ccbba737fef818e41a714bfc1 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Sep 3 16:29:26 2015 +0200 Ajout d'un adapter Gson pour les Class Summary of changes: .../observe/services/dto/gson/ClassAdapter.java | 42 ++++++++++++++++++++++ .../services/dto/gson/ObserveDtoGsonSupplier.java | 1 + 2 files changed, 43 insertions(+) create mode 100644 observe-services-model/src/main/java/fr/ird/observe/services/dto/gson/ClassAdapter.java -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository observe. See http://git.codelutin.com/observe.git commit 88e7990863c7a06ccbba737fef818e41a714bfc1 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Sep 3 16:29:26 2015 +0200 Ajout d'un adapter Gson pour les Class --- .../observe/services/dto/gson/ClassAdapter.java | 42 ++++++++++++++++++++++ .../services/dto/gson/ObserveDtoGsonSupplier.java | 1 + 2 files changed, 43 insertions(+) diff --git a/observe-services-model/src/main/java/fr/ird/observe/services/dto/gson/ClassAdapter.java b/observe-services-model/src/main/java/fr/ird/observe/services/dto/gson/ClassAdapter.java new file mode 100644 index 0000000..e2e669d --- /dev/null +++ b/observe-services-model/src/main/java/fr/ird/observe/services/dto/gson/ClassAdapter.java @@ -0,0 +1,42 @@ +package fr.ird.observe.services.dto.gson; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.lang.reflect.Type; + +/** + * @author Arnaud Thimel - thimel@codelutin.com + */ +public class ClassAdapter implements JsonSerializer<Class<?>>, JsonDeserializer<Class<?>> { + + private static final Log log = LogFactory.getLog(ClassAdapter.class); + + @Override + public JsonElement serialize(Class<?> src, Type typeOfSrc, JsonSerializationContext context) { + return context.serialize(src.getCanonicalName(), String.class); + + } + + @Override + public Class<?> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + + String className = json.getAsString(); + try { + Class<?> result = Class.forName(className); + return result; + } catch (ClassNotFoundException cnfe) { + if (log.isErrorEnabled()) { + log.error("An exception occurred", cnfe); + } + throw new JsonParseException("Class not found: " + className, cnfe); + } + } + +} diff --git a/observe-services-model/src/main/java/fr/ird/observe/services/dto/gson/ObserveDtoGsonSupplier.java b/observe-services-model/src/main/java/fr/ird/observe/services/dto/gson/ObserveDtoGsonSupplier.java index 0904065..2e29717 100644 --- a/observe-services-model/src/main/java/fr/ird/observe/services/dto/gson/ObserveDtoGsonSupplier.java +++ b/observe-services-model/src/main/java/fr/ird/observe/services/dto/gson/ObserveDtoGsonSupplier.java @@ -50,6 +50,7 @@ public class ObserveDtoGsonSupplier implements Supplier<Gson> { gsonBuilder.registerTypeAdapter(Date.class, new DateAdapter()); gsonBuilder.registerTypeAdapter(Timestamp.class, new DateAdapter()); gsonBuilder.registerTypeAdapter(java.sql.Date.class, new DateAdapter()); + gsonBuilder.registerTypeAdapter(Class.class, new ClassAdapter()); } return gsonBuilder; -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
participants (1)
-
codelutin.com scm