Java Object Save writeObjectToFile(String filename, T object)

Here you can find the source of writeObjectToFile(String filename, T object)

Description

write the object to a json file

License

Apache License

Parameter

Parameter Description
file a parameter
object a parameter

Declaration

public static <T> void writeObjectToFile(String filename, T object) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.io.IOException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class Main {
    /**/* w  w w.j av a2s  .  c om*/
     * write the object to a json file
     * @param file
     * @param object
     */
    public static <T> void writeObjectToFile(String filename, T object) {
        ObjectMapper mapper = new ObjectMapper();
        File file = new File(filename);
        try {
            mapper.writeValue(file, object);
        } catch (IOException e) {
            System.err.println("error write object as json file: " + object + " for " + e);
        }
    }
}

Related

  1. writeObjectToFile(Object object, File file)
  2. writeObjectToFile(Object oObject, File destDir, String filename)
  3. writeObjectToFile(String dirname, String filename, Object obj)
  4. writeObjectToFile(String fileName, Object obj)
  5. writeObjectToFile(String filename, Serializable s)
  6. writeObjectToFile(String outputFileName, Object toWrite, boolean append)
  7. writeObjectToFile(T object, File fileHandle)
  8. writeObjectToFileNoExceptions(Object o, String filename)