Added junit intigration and fixed issues iwth object mapper

This commit is contained in:
Isaac Parenteau
2019-07-21 11:52:25 -05:00
parent 0c3739c8db
commit 79f913cc6d
4 changed files with 11 additions and 19 deletions

View File

@@ -88,6 +88,9 @@ public class ObjectMapperHelper {
*/
public static <T> ObjectMapperResults<T> readValue(Object src, Class<T> clazz) {
try {
if (src instanceof String) {
return readValue((String)src, clazz);
}
return readValue(mapper.writeValueAsString(src), clazz);
} catch (Exception ex) {
return new ObjectMapperResults<T>(ex);
@@ -116,6 +119,9 @@ public class ObjectMapperHelper {
*/
public static <T, L extends Collection<?>> ObjectMapperListResults<List<T>> readListValue(Object object, Class<T> objectClass, Class<L> listClass) {
try {
if (object instanceof String) {
return readListValue((String)object, objectClass, listClass);
}
return readListValue(mapper.writeValueAsString(object), objectClass, listClass);
} catch (Exception ex) {
return new ObjectMapperListResults<>(ex);
@@ -131,7 +137,7 @@ public class ObjectMapperHelper {
* @param <L> The expect class of the list
* @return the object list populated with the data in the json string
*/
public static <T, L extends Collection<?>> ObjectMapperListResults<List<T>> readListValue(String src, Class<T> objectClass, Class<L> listClass) {
public static <T, L extends Collection<?>> ObjectMapperListResults<List<T>> readListValue(String src, Class<T> objectClass, Class<L> listClass) {
try {
List<T> item = mapper.readValue(src, mapper.getTypeFactory().constructCollectionType(listClass, objectClass));
return new ObjectMapperListResults<>(item);