Package com.firefly.utils.json

Source Code of com.firefly.utils.json.Json

package com.firefly.utils.json;

import java.io.IOException;
import java.io.Writer;

import com.firefly.utils.io.StringWriter;

public abstract class Json {
  public static String toJson(Object obj) {
    String ret = null;
    StringWriter stringWriter = new StringWriter();
    try {
      ret = new JsonSerializer(stringWriter).toJson(obj).toString();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      stringWriter.close();
    }
    return ret;
  }

  public static void toJson(Object obj, Writer writer) {
    try {
      new JsonSerializer(writer).toJson(obj);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
TOP

Related Classes of com.firefly.utils.json.Json

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.