Package com.loja.util

Source Code of com.loja.util.JsonUtil

package com.loja.util;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;

public class JsonUtil {
 
  @SuppressWarnings("unchecked")
  public String toJson(Class classe, Object object) {
    XStream xstream = new XStream(new JettisonMappedXmlDriver());
    xstream.setMode(XStream.NO_REFERENCES);
    xstream.alias("usuario", classe);
    return xstream.toXML(object);
  }
 
  @SuppressWarnings("unchecked")
  public Object fromJson(Class classe, String element) {
    XStream xstream = new XStream(new JettisonMappedXmlDriver());
    xstream.setMode(XStream.NO_REFERENCES);
    xstream.alias(classe.getSimpleName().toLowerCase(), classe);
    return xstream.fromXML(element);
  }

}
TOP

Related Classes of com.loja.util.JsonUtil

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.