import com.google.gson.Gson; import com.google.gson.GsonBuilder; public class App { public static void main(String[] args) throws Exception { Employee emp = new Employee("Csendes Imre", "Szeged", 342); GsonBuilder builder = new GsonBuilder(); builder.setPrettyPrinting(); Gson gson = builder.create(); String jsonStr = gson.toJson(emp); System.out.println(jsonStr); } }