/* * Serialization helper Class */public class Serializehelper {private static Objectmapper Objectmapper = new Objectmapper (); /** * Serializes an object into a JSON string * * @param object * @return JSON String * @throws IOException * @throws Js Onmappingexception * @throws jsongenerationexception */Public String Serialize (object object) throws Jsong Enerationexception, Jsonmappingexception, IOException {Writer write = new StringWriter (); Objectmapper.writevalue (write, object); return write.tostring (); }/** * Deserializes JSON string into object * * @param object * @return JSON String * @throws IOException * @throws jsonmappingexception * @throws jsonparseexception * * Public <T> T Deserialize (String JSON, C Lass<t> clazz) throws Jsonparseexception, Jsonmappingexception, IOException {Object object = Objectmapper. ReadValue (JSON, Typefactory.rawclass (Clazz)); Return (T) object; }}
JSON serialization of Java