Package cz.tvrzna.jackie
Class Jackie
- java.lang.Object
-
- cz.tvrzna.jackie.Jackie
-
public class Jackie extends Object
MainJackieclass, that provides converting of objects to JSON asStringand JSONStringto objects.- Author:
- michalt
-
-
Constructor Summary
Constructors Constructor Description Jackie()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> TfromJson(String json, Class<T> clazz)Converts single object or array from JSON to instance ofclazz.<T> TfromJson(String json, Class<T> clazz, Class<?> subClazz)Converts List or array from JSON.<T> TfromJson(String json, Class<T> clazz, Class<?> keyClazz, Class<?> valueClazz)Converts Map from JSON.<T> StringtoJson(T object)Converts single object into JSON asString.
-
-
-
Method Detail
-
toJson
public <T> String toJson(T object)
Converts single object into JSON asString.- Type Parameters:
T- the generic type- Parameters:
object- the object- Returns:
- the string
-
fromJson
public <T> T fromJson(String json, Class<T> clazz)
Converts single object or array from JSON to instance ofclazz.
Ifclazzis going to be aList, @see Jackie#fromJson(String, Class, Class) to define the Type of list.
Ifclazzis going to beMap, @see Jackie#fromJson(String, Class, Class, Class) to define key and value classes, if you want to avoid to be usedStringandObject.- Type Parameters:
T- the generic type- Parameters:
json- the jsonclazz- the clazz- Returns:
- the t
-
fromJson
public <T> T fromJson(String json, Class<T> clazz, Class<?> subClazz)
Converts List or array from JSON. If it converts list,subClazzneeds to be defined as generic type of List.- Type Parameters:
T- the generic type- Parameters:
json- the jsonclazz- the clazzsubClazz- the sub clazz- Returns:
- the t
-
fromJson
public <T> T fromJson(String json, Class<T> clazz, Class<?> keyClazz, Class<?> valueClazz)
Converts Map from JSON. It needs to have definedkeyClazzas class of Key attribute andvalueClazzas class of Value attribute.- Type Parameters:
T- the generic type- Parameters:
json- the jsonclazz- the clazzkeyClazz- the key clazzvalueClazz- the value clazz- Returns:
- the t
-
-