Created
January 18, 2019 18:01
-
-
Save azumamagus/ef018ebdca299e7aaff6f242d5c5d111 to your computer and use it in GitHub Desktop.
AlunoConverter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.teste.agenda.converter; | |
import org.json.JSONException; | |
import org.json.JSONStringer; | |
import java.util.List; | |
import br.com.teste.agenda.modelo.Aluno; | |
public class AlunoConverter { | |
public String toJson(List<Aluno> alunos) { | |
try { | |
JSONStringer jsonStringer = new JSONStringer(); | |
jsonStringer.object().key("list").array() | |
.object().key("sluno").array(); | |
for (Aluno aluno : alunos) { | |
jsonStringer.object() | |
.key("id").value(aluno.getId()) | |
.key("nome").value(aluno.getNome()) | |
.key("telefone").value(aluno.getTelefone()) | |
.key("endereco").value(aluno.getEndereco()) | |
.key("site").value(aluno.getSite()) | |
.key("nota").value(aluno.getNota()) | |
.endObject(); | |
} | |
return jsonStringer.endArray().endObject() | |
.endArray().endObject().toString(); | |
} catch (JSONException e) { | |
e.printStackTrace(); | |
} | |
return ""; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment