Não dá cara, meu projeto tá todo bagunçado e tem umas coisas que eu nem testei ainda. Mas o que eu posso mandar são as partes que mexem com o arquivo e a classe User. O resto do projeto não tem nada a ver com o arquivo.
Classe User:
package com.tkfentretenimento.meusdados.model;
import java.util.ArrayList;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public class User {
private StringProperty Name = new SimpleStringProperty();
private StringProperty Email = new SimpleStringProperty();
private BooleanProperty Gender = new SimpleBooleanProperty();
private StringProperty Picture = new SimpleStringProperty();
private StringProperty googleId = new SimpleStringProperty();
private ArrayList<String> Likes = new ArrayList<String>();
private ArrayList<Event> Events = new ArrayList<Event>();
public User(String googleId2, String n, String em, boolean g, String p, ArrayList<String> l) {
this.Name.set(formatName(n));
this.Email.set(em);
this.Gender.set(g);
this.Picture.set(p);
this.Likes = l;
this.googleId.set(googleId2);;
}
public User(){
}
private String formatName(String n){
n = n.replaceFirst(" ", "");
String r = "";
String[] split = n.split(" ");
for(String str : split){
str = str.substring(0,1).toUpperCase().concat(str.substring(1));
r+=str;
}
return r;
}
public final StringProperty NameProperty() {
return this.Name;
}
public final String getName() {
return this.NameProperty().get();
}
public final void setName(final String Name) {
this.NameProperty().set(Name);
}
public final StringProperty emailProperty() {
return this.Email;
}
public final String getEmail() {
return this.emailProperty().get();
}
public final void setEmail(final String email) {
this.emailProperty().set(email);
}
public final BooleanProperty GenderProperty() {
return this.Gender;
}
public final boolean isGender() {
return this.GenderProperty().get();
}
public final void setGender(final boolean Gender) {
this.GenderProperty().set(Gender);
}
public final StringProperty PictureProperty() {
return this.Picture;
}
public final String getPicture() {
return this.PictureProperty().get();
}
public final void setPicture(final String Picture) {
this.PictureProperty().set(Picture);
}
public ArrayList<String> getLikes() {
return Likes;
}
public void setLikes(ArrayList<String> likes) {
Likes = likes;
}
public ArrayList<Event> getEvents() {
return Events;
}
public void setEvents(ArrayList<Event> events) {
this.Events = events;
}
public final StringProperty googleIdProperty() {
return this.googleId;
}
public final String getGoogleId() {
return this.googleIdProperty().get();
}
public final void setGoogleId(final String googleId) {
this.googleIdProperty().set(googleId);
}
}
Escrevendo o User:
String json = null;
Gson gson = new Gson();
json = gson.toJson(currentUser);
System.out.println(json);
File fJson = new File(Methods.MakeProgramFolder().getAbsolutePath()+"/user.json");
if(!fJson.exists()){fJson.createNewFile();}
BufferedWriter buffWrite = new BufferedWriter(new FileWriter(fJson));
buffWrite.append(json);
buffWrite.close();
Lendo o User:
File fJson = new File(Methods.MakeProgramFolder().getAbsolutePath()+"/user.json");
if(!fJson.exists()){fJson.createNewFile();}
BufferedReader br = new BufferedReader(new FileReader(fJson));
String line;
String json = "";
while((line = br.readLine()) !=null){
json+=line;
}
String u = new String(json.getBytes(), "UTF-8");
Gson gson = new Gson();
User user = gson.fromJson(u, User.class);
System.out.println(u);
//UserDAO.signInOffline(user);