1 34 35 36 package com.micronova.util.codec; 37 38 import com.micronova.util.*; 39 40 public class CodecJSON extends Codec 41 { 42 43 44 public static Object decode(Object object, Object control) throws Exception 45 { 46 if (object != null) 47 { 48 NestedMap controlMap = TypeUtil.isNestedMap(control); 49 50 object = StringUtil.decodeJSON(object.toString(), !TypeUtil.isFalse(controlMap.get("allowUnquoted"))); 51 } 52 53 return object; 54 } 55 56 public static Object decode(Object object) throws Exception 57 { 58 return decode(object, null); 59 } 60 61 62 63 public static Object encode(Object object, Object control) 64 { 65 if (object != null) 66 { 67 NestedMap controlMap = TypeUtil.isNestedMap(control); 68 String quote = controlMap.getString("quote", "\""); 69 boolean doesEncode = !TypeUtil.isFalse(controlMap.get("doesEncode")); 70 71 object = StringUtil.encodeJSON(object, quote, doesEncode); 72 } 73 74 return object; 75 } 76 77 public static Object encode(Object object) 78 { 79 return encode(object, null); 80 } 81 } 82 | Popular Tags |