-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Json
springside edited this page Apr 4, 2012
·
7 revisions
##JsonMapper in SpringSide-Core JsonMapper是对Jackson的Object Mapper的简单封装,提供如下函数:
- static JsonMapper buildNonNullMapper()及其他,提供构造NON_NULL,NON_EMPTY,NON_DEFAULT值Mapper的工厂方法,详见后面的例子。
- String toJson(Object object), 将Object,Collection,数组序列化成JSON字符串。Jackson的原生API还可以序列化到byte[]或File/Outputstream/Writer,可视情况使用.
- T fromJson(String jsonString, Class clazz),从JSON字符串反序列到Object,这里仅支持POJO或简单Collection如List.
- T fromJson(String jsonString, JavaType javaType),从JSON字符串反序列化复杂Collection如List。
- JavaType createCollectionType(Class> collectionClass, Class>... elementClasses), 構造上面函数需要的泛型的Collection Type,如HashMap<String,MyBean>, 则调用(HashMap.class,String.class, MyBean.class)
- T update(String jsonString, T object),當JSON裡只含有Bean的部分屬性時,更 新一個已存在Bean,只覆蓋該部分的屬性.
- String toJsonP(String functionName, Object object) 輸出JSONP格式數據.
- enableEnumUseToString(), 設定是否使用Enum的toString函數來讀寫Enum,详见后面的例子。
##JSonDemo in Showcase