Google Firebase serializa / deserializa

Eu sou novo na FIrebase e tenho 2 problemas com isso que podem estair conectados. Primeiro é ao save minha list de events.

//creating event TVEvent tvEvent = new TVEvent(etTitle.getText().toString()); User host = ResourceManager.getUser(); String date = etDate.getText().toString(); String location = etLocation.getText().toString(); TVSet tvset = ResourceManager.getUser().getTvSets().get(0); Event ev = new Event(tvEvent, host, date, location, tvset); ResourceManager.addEvent(ev); mDatabase.child("events").child(host.getId()).setValue(ResourceManager.getEvents()); //getEvents() returns a list of events 

isto é o que eu recebo no console insira a descrição da imagem aqui

  • Como se conectair a mais de um database da base de dados de firebows de uma aplicação Android
  • Como usair a consulta do Firebase igual a (valor, key)?
  • A forma como o database da base de dados da Firebase inicia rapidamente as contagens seguras?
  • Como excluir do database em tempo real do firebase?
  • Melhores práticas selecionando database paira aplicativo móvel
  • Classifique corretamente os nós dos mais recentes aos mais antigos
  • O problema é que tvevent e tv set têm mais attributes do que estes. Quando eu depurado paira descobrir por que isso foi criado com todos os seus attributes que foi um pouco estranho. Por enquanto, no entanto, não sei se isso é um problema, pois não consigo recuperair o tvset e o return do database. Quando eu faço o seguinte, obtenho o nulo.

     mDatabase.child("events").addListenerForSingleValueEvent( new ValueEventListener() { @Oviewride public void onDataChange(DataSnapshot dataSnapshot) { System.out.println("Cheking for events"); //GenericTypeIndicator<List<Event>> t = new GenericTypeIndicator<List<Event>>() {}; //List<Event> e = dataSnapshot.getValue(t); for (DataSnapshot messageSnapshot: dataSnapshot.getChildren()) { GenericTypeIndicator<List<Event>> t = new GenericTypeIndicator<List<Event>>() {}; List<Event> list = messageSnapshot.getValue(t); if (list != null) { for (Event ev : list) { System.out.println("Event found"); ResourceManager.addEvent(ev); } } } } @Oviewride public void onCancelled(DatabaseError databaseError) { } }); } mDatabase.child("events").addListenerForSingleValueEvent( new ValueEventListener() { @Oviewride public void onDataChange(DataSnapshot dataSnapshot) { System.out.println("Cheking for events"); //GenericTypeIndicator<List<Event>> t = new GenericTypeIndicator<List<Event>>() {}; //List<Event> e = dataSnapshot.getValue(t); for (DataSnapshot messageSnapshot: dataSnapshot.getChildren()) { GenericTypeIndicator<List<Event>> t = new GenericTypeIndicator<List<Event>>() {}; List<Event> list = messageSnapshot.getValue(t); if (list != null) { for (Event ev : list) { System.out.println("Event found"); ResourceManager.addEvent(ev); } } } } @Oviewride public void onCancelled(DatabaseError databaseError) { } }); } mDatabase.child("events").addListenerForSingleValueEvent( new ValueEventListener() { @Oviewride public void onDataChange(DataSnapshot dataSnapshot) { System.out.println("Cheking for events"); //GenericTypeIndicator<List<Event>> t = new GenericTypeIndicator<List<Event>>() {}; //List<Event> e = dataSnapshot.getValue(t); for (DataSnapshot messageSnapshot: dataSnapshot.getChildren()) { GenericTypeIndicator<List<Event>> t = new GenericTypeIndicator<List<Event>>() {}; List<Event> list = messageSnapshot.getValue(t); if (list != null) { for (Event ev : list) { System.out.println("Event found"); ResourceManager.addEvent(ev); } } } } @Oviewride public void onCancelled(DatabaseError databaseError) { } }); } mDatabase.child("events").addListenerForSingleValueEvent( new ValueEventListener() { @Oviewride public void onDataChange(DataSnapshot dataSnapshot) { System.out.println("Cheking for events"); //GenericTypeIndicator<List<Event>> t = new GenericTypeIndicator<List<Event>>() {}; //List<Event> e = dataSnapshot.getValue(t); for (DataSnapshot messageSnapshot: dataSnapshot.getChildren()) { GenericTypeIndicator<List<Event>> t = new GenericTypeIndicator<List<Event>>() {}; List<Event> list = messageSnapshot.getValue(t); if (list != null) { for (Event ev : list) { System.out.println("Event found"); ResourceManager.addEvent(ev); } } } } @Oviewride public void onCancelled(DatabaseError databaseError) { } }); } mDatabase.child("events").addListenerForSingleValueEvent( new ValueEventListener() { @Oviewride public void onDataChange(DataSnapshot dataSnapshot) { System.out.println("Cheking for events"); //GenericTypeIndicator<List<Event>> t = new GenericTypeIndicator<List<Event>>() {}; //List<Event> e = dataSnapshot.getValue(t); for (DataSnapshot messageSnapshot: dataSnapshot.getChildren()) { GenericTypeIndicator<List<Event>> t = new GenericTypeIndicator<List<Event>>() {}; List<Event> list = messageSnapshot.getValue(t); if (list != null) { for (Event ev : list) { System.out.println("Event found"); ResourceManager.addEvent(ev); } } } } @Oviewride public void onCancelled(DatabaseError databaseError) { } }); } mDatabase.child("events").addListenerForSingleValueEvent( new ValueEventListener() { @Oviewride public void onDataChange(DataSnapshot dataSnapshot) { System.out.println("Cheking for events"); //GenericTypeIndicator<List<Event>> t = new GenericTypeIndicator<List<Event>>() {}; //List<Event> e = dataSnapshot.getValue(t); for (DataSnapshot messageSnapshot: dataSnapshot.getChildren()) { GenericTypeIndicator<List<Event>> t = new GenericTypeIndicator<List<Event>>() {}; List<Event> list = messageSnapshot.getValue(t); if (list != null) { for (Event ev : list) { System.out.println("Event found"); ResourceManager.addEvent(ev); } } } } @Oviewride public void onCancelled(DatabaseError databaseError) { } }); 

    Não sei por que esses valores são nulos, pois vejo que eles não estão no console da firebase. Então qual é o problema?

     @IgnoreExtraProperties public class Event { private TVEvent tvEvent; private User host; private Date date; private String location; private TVSet tvSet; private List<User> attending; public Event(){ } public Event(TVEvent tvEvent, User host, String date, String location, TVSet tvset){ this.tvSet = tvset; this.tvEvent = tvEvent; this.host = host; try { this.date = new SimpleDateFormat("dd/MM/yyyy").pairse(date); } catch (PairseException e) { e.printStackTrace(); } this.location = location; attending = new ArrayList<>(); } public User getHost() { return host; } public String getLocation() { return location; } public TVSet getTVSet() { return tvSet; } public Date getDate() { return date; } public TVEvent getTVEvent() { return tvEvent; } public void addAttending(User user){ attending.add(user); } public List<User> getAttending(){ return attending; } } } @IgnoreExtraProperties public class Event { private TVEvent tvEvent; private User host; private Date date; private String location; private TVSet tvSet; private List<User> attending; public Event(){ } public Event(TVEvent tvEvent, User host, String date, String location, TVSet tvset){ this.tvSet = tvset; this.tvEvent = tvEvent; this.host = host; try { this.date = new SimpleDateFormat("dd/MM/yyyy").pairse(date); } catch (PairseException e) { e.printStackTrace(); } this.location = location; attending = new ArrayList<>(); } public User getHost() { return host; } public String getLocation() { return location; } public TVSet getTVSet() { return tvSet; } public Date getDate() { return date; } public TVEvent getTVEvent() { return tvEvent; } public void addAttending(User user){ attending.add(user); } public List<User> getAttending(){ return attending; } } this.host = host; @IgnoreExtraProperties public class Event { private TVEvent tvEvent; private User host; private Date date; private String location; private TVSet tvSet; private List<User> attending; public Event(){ } public Event(TVEvent tvEvent, User host, String date, String location, TVSet tvset){ this.tvSet = tvset; this.tvEvent = tvEvent; this.host = host; try { this.date = new SimpleDateFormat("dd/MM/yyyy").pairse(date); } catch (PairseException e) { e.printStackTrace(); } this.location = location; attending = new ArrayList<>(); } public User getHost() { return host; } public String getLocation() { return location; } public TVSet getTVSet() { return tvSet; } public Date getDate() { return date; } public TVEvent getTVEvent() { return tvEvent; } public void addAttending(User user){ attending.add(user); } public List<User> getAttending(){ return attending; } } } @IgnoreExtraProperties public class Event { private TVEvent tvEvent; private User host; private Date date; private String location; private TVSet tvSet; private List<User> attending; public Event(){ } public Event(TVEvent tvEvent, User host, String date, String location, TVSet tvset){ this.tvSet = tvset; this.tvEvent = tvEvent; this.host = host; try { this.date = new SimpleDateFormat("dd/MM/yyyy").pairse(date); } catch (PairseException e) { e.printStackTrace(); } this.location = location; attending = new ArrayList<>(); } public User getHost() { return host; } public String getLocation() { return location; } public TVSet getTVSet() { return tvSet; } public Date getDate() { return date; } public TVEvent getTVEvent() { return tvEvent; } public void addAttending(User user){ attending.add(user); } public List<User> getAttending(){ return attending; } } } @IgnoreExtraProperties public class Event { private TVEvent tvEvent; private User host; private Date date; private String location; private TVSet tvSet; private List<User> attending; public Event(){ } public Event(TVEvent tvEvent, User host, String date, String location, TVSet tvset){ this.tvSet = tvset; this.tvEvent = tvEvent; this.host = host; try { this.date = new SimpleDateFormat("dd/MM/yyyy").pairse(date); } catch (PairseException e) { e.printStackTrace(); } this.location = location; attending = new ArrayList<>(); } public User getHost() { return host; } public String getLocation() { return location; } public TVSet getTVSet() { return tvSet; } public Date getDate() { return date; } public TVEvent getTVEvent() { return tvEvent; } public void addAttending(User user){ attending.add(user); } public List<User> getAttending(){ return attending; } } } @IgnoreExtraProperties public class Event { private TVEvent tvEvent; private User host; private Date date; private String location; private TVSet tvSet; private List<User> attending; public Event(){ } public Event(TVEvent tvEvent, User host, String date, String location, TVSet tvset){ this.tvSet = tvset; this.tvEvent = tvEvent; this.host = host; try { this.date = new SimpleDateFormat("dd/MM/yyyy").pairse(date); } catch (PairseException e) { e.printStackTrace(); } this.location = location; attending = new ArrayList<>(); } public User getHost() { return host; } public String getLocation() { return location; } public TVSet getTVSet() { return tvSet; } public Date getDate() { return date; } public TVEvent getTVEvent() { return tvEvent; } public void addAttending(User user){ attending.add(user); } public List<User> getAttending(){ return attending; } } } @IgnoreExtraProperties public class Event { private TVEvent tvEvent; private User host; private Date date; private String location; private TVSet tvSet; private List<User> attending; public Event(){ } public Event(TVEvent tvEvent, User host, String date, String location, TVSet tvset){ this.tvSet = tvset; this.tvEvent = tvEvent; this.host = host; try { this.date = new SimpleDateFormat("dd/MM/yyyy").pairse(date); } catch (PairseException e) { e.printStackTrace(); } this.location = location; attending = new ArrayList<>(); } public User getHost() { return host; } public String getLocation() { return location; } public TVSet getTVSet() { return tvSet; } public Date getDate() { return date; } public TVEvent getTVEvent() { return tvEvent; } public void addAttending(User user){ attending.add(user); } public List<User> getAttending(){ return attending; } } } @IgnoreExtraProperties public class Event { private TVEvent tvEvent; private User host; private Date date; private String location; private TVSet tvSet; private List<User> attending; public Event(){ } public Event(TVEvent tvEvent, User host, String date, String location, TVSet tvset){ this.tvSet = tvset; this.tvEvent = tvEvent; this.host = host; try { this.date = new SimpleDateFormat("dd/MM/yyyy").pairse(date); } catch (PairseException e) { e.printStackTrace(); } this.location = location; attending = new ArrayList<>(); } public User getHost() { return host; } public String getLocation() { return location; } public TVSet getTVSet() { return tvSet; } public Date getDate() { return date; } public TVEvent getTVEvent() { return tvEvent; } public void addAttending(User user){ attending.add(user); } public List<User> getAttending(){ return attending; } } } @IgnoreExtraProperties public class Event { private TVEvent tvEvent; private User host; private Date date; private String location; private TVSet tvSet; private List<User> attending; public Event(){ } public Event(TVEvent tvEvent, User host, String date, String location, TVSet tvset){ this.tvSet = tvset; this.tvEvent = tvEvent; this.host = host; try { this.date = new SimpleDateFormat("dd/MM/yyyy").pairse(date); } catch (PairseException e) { e.printStackTrace(); } this.location = location; attending = new ArrayList<>(); } public User getHost() { return host; } public String getLocation() { return location; } public TVSet getTVSet() { return tvSet; } public Date getDate() { return date; } public TVEvent getTVEvent() { return tvEvent; } public void addAttending(User user){ attending.add(user); } public List<User> getAttending(){ return attending; } } } @IgnoreExtraProperties public class Event { private TVEvent tvEvent; private User host; private Date date; private String location; private TVSet tvSet; private List<User> attending; public Event(){ } public Event(TVEvent tvEvent, User host, String date, String location, TVSet tvset){ this.tvSet = tvset; this.tvEvent = tvEvent; this.host = host; try { this.date = new SimpleDateFormat("dd/MM/yyyy").pairse(date); } catch (PairseException e) { e.printStackTrace(); } this.location = location; attending = new ArrayList<>(); } public User getHost() { return host; } public String getLocation() { return location; } public TVSet getTVSet() { return tvSet; } public Date getDate() { return date; } public TVEvent getTVEvent() { return tvEvent; } public void addAttending(User user){ attending.add(user); } public List<User> getAttending(){ return attending; } } } @IgnoreExtraProperties public class Event { private TVEvent tvEvent; private User host; private Date date; private String location; private TVSet tvSet; private List<User> attending; public Event(){ } public Event(TVEvent tvEvent, User host, String date, String location, TVSet tvset){ this.tvSet = tvset; this.tvEvent = tvEvent; this.host = host; try { this.date = new SimpleDateFormat("dd/MM/yyyy").pairse(date); } catch (PairseException e) { e.printStackTrace(); } this.location = location; attending = new ArrayList<>(); } public User getHost() { return host; } public String getLocation() { return location; } public TVSet getTVSet() { return tvSet; } public Date getDate() { return date; } public TVEvent getTVEvent() { return tvEvent; } public void addAttending(User user){ attending.add(user); } public List<User> getAttending(){ return attending; } } } @IgnoreExtraProperties public class Event { private TVEvent tvEvent; private User host; private Date date; private String location; private TVSet tvSet; private List<User> attending; public Event(){ } public Event(TVEvent tvEvent, User host, String date, String location, TVSet tvset){ this.tvSet = tvset; this.tvEvent = tvEvent; this.host = host; try { this.date = new SimpleDateFormat("dd/MM/yyyy").pairse(date); } catch (PairseException e) { e.printStackTrace(); } this.location = location; attending = new ArrayList<>(); } public User getHost() { return host; } public String getLocation() { return location; } public TVSet getTVSet() { return tvSet; } public Date getDate() { return date; } public TVEvent getTVEvent() { return tvEvent; } public void addAttending(User user){ attending.add(user); } public List<User> getAttending(){ return attending; } } 

    Como TVSet e TVEvent não são desertificados corretamente, eu publicairei apenas um deles:

     @IgnoreExtraProperties public class TVSet { private String title; private String imageFile; //private Bitmap picture; public TVSet(){ } public TVSet(String title){ this.title = title; } public TVSet(Bitmap picture){ imageFile = compressImage(picture); } public void setTitle(String title){ this.title = title; } public String getTitle() { return title; } private String compressImage(Bitmap image){ ByteArrayOutputStream bYtE = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.PNG, 100, bYtE); //image.recycle(); byte[] byteArray = bYtE.toByteArray(); String imageFile = Base64.encodeToString(byteArray, Base64.DEFAULT); return imageFile; } @Exclude public Bitmap getImage() { byte[] decodedString = Base64.decode(imageFile, Base64.DEFAULT); Bitmap bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); return bitmap; } public String getImageFile(){ return imageFile; } } } @IgnoreExtraProperties public class TVSet { private String title; private String imageFile; //private Bitmap picture; public TVSet(){ } public TVSet(String title){ this.title = title; } public TVSet(Bitmap picture){ imageFile = compressImage(picture); } public void setTitle(String title){ this.title = title; } public String getTitle() { return title; } private String compressImage(Bitmap image){ ByteArrayOutputStream bYtE = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.PNG, 100, bYtE); //image.recycle(); byte[] byteArray = bYtE.toByteArray(); String imageFile = Base64.encodeToString(byteArray, Base64.DEFAULT); return imageFile; } @Exclude public Bitmap getImage() { byte[] decodedString = Base64.decode(imageFile, Base64.DEFAULT); Bitmap bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); return bitmap; } public String getImageFile(){ return imageFile; } } } @IgnoreExtraProperties public class TVSet { private String title; private String imageFile; //private Bitmap picture; public TVSet(){ } public TVSet(String title){ this.title = title; } public TVSet(Bitmap picture){ imageFile = compressImage(picture); } public void setTitle(String title){ this.title = title; } public String getTitle() { return title; } private String compressImage(Bitmap image){ ByteArrayOutputStream bYtE = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.PNG, 100, bYtE); //image.recycle(); byte[] byteArray = bYtE.toByteArray(); String imageFile = Base64.encodeToString(byteArray, Base64.DEFAULT); return imageFile; } @Exclude public Bitmap getImage() { byte[] decodedString = Base64.decode(imageFile, Base64.DEFAULT); Bitmap bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); return bitmap; } public String getImageFile(){ return imageFile; } } } @IgnoreExtraProperties public class TVSet { private String title; private String imageFile; //private Bitmap picture; public TVSet(){ } public TVSet(String title){ this.title = title; } public TVSet(Bitmap picture){ imageFile = compressImage(picture); } public void setTitle(String title){ this.title = title; } public String getTitle() { return title; } private String compressImage(Bitmap image){ ByteArrayOutputStream bYtE = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.PNG, 100, bYtE); //image.recycle(); byte[] byteArray = bYtE.toByteArray(); String imageFile = Base64.encodeToString(byteArray, Base64.DEFAULT); return imageFile; } @Exclude public Bitmap getImage() { byte[] decodedString = Base64.decode(imageFile, Base64.DEFAULT); Bitmap bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); return bitmap; } public String getImageFile(){ return imageFile; } } } @IgnoreExtraProperties public class TVSet { private String title; private String imageFile; //private Bitmap picture; public TVSet(){ } public TVSet(String title){ this.title = title; } public TVSet(Bitmap picture){ imageFile = compressImage(picture); } public void setTitle(String title){ this.title = title; } public String getTitle() { return title; } private String compressImage(Bitmap image){ ByteArrayOutputStream bYtE = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.PNG, 100, bYtE); //image.recycle(); byte[] byteArray = bYtE.toByteArray(); String imageFile = Base64.encodeToString(byteArray, Base64.DEFAULT); return imageFile; } @Exclude public Bitmap getImage() { byte[] decodedString = Base64.decode(imageFile, Base64.DEFAULT); Bitmap bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); return bitmap; } public String getImageFile(){ return imageFile; } } } @IgnoreExtraProperties public class TVSet { private String title; private String imageFile; //private Bitmap picture; public TVSet(){ } public TVSet(String title){ this.title = title; } public TVSet(Bitmap picture){ imageFile = compressImage(picture); } public void setTitle(String title){ this.title = title; } public String getTitle() { return title; } private String compressImage(Bitmap image){ ByteArrayOutputStream bYtE = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.PNG, 100, bYtE); //image.recycle(); byte[] byteArray = bYtE.toByteArray(); String imageFile = Base64.encodeToString(byteArray, Base64.DEFAULT); return imageFile; } @Exclude public Bitmap getImage() { byte[] decodedString = Base64.decode(imageFile, Base64.DEFAULT); Bitmap bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); return bitmap; } public String getImageFile(){ return imageFile; } } } @IgnoreExtraProperties public class TVSet { private String title; private String imageFile; //private Bitmap picture; public TVSet(){ } public TVSet(String title){ this.title = title; } public TVSet(Bitmap picture){ imageFile = compressImage(picture); } public void setTitle(String title){ this.title = title; } public String getTitle() { return title; } private String compressImage(Bitmap image){ ByteArrayOutputStream bYtE = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.PNG, 100, bYtE); //image.recycle(); byte[] byteArray = bYtE.toByteArray(); String imageFile = Base64.encodeToString(byteArray, Base64.DEFAULT); return imageFile; } @Exclude public Bitmap getImage() { byte[] decodedString = Base64.decode(imageFile, Base64.DEFAULT); Bitmap bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); return bitmap; } public String getImageFile(){ return imageFile; } } } @IgnoreExtraProperties public class TVSet { private String title; private String imageFile; //private Bitmap picture; public TVSet(){ } public TVSet(String title){ this.title = title; } public TVSet(Bitmap picture){ imageFile = compressImage(picture); } public void setTitle(String title){ this.title = title; } public String getTitle() { return title; } private String compressImage(Bitmap image){ ByteArrayOutputStream bYtE = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.PNG, 100, bYtE); //image.recycle(); byte[] byteArray = bYtE.toByteArray(); String imageFile = Base64.encodeToString(byteArray, Base64.DEFAULT); return imageFile; } @Exclude public Bitmap getImage() { byte[] decodedString = Base64.decode(imageFile, Base64.DEFAULT); Bitmap bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); return bitmap; } public String getImageFile(){ return imageFile; } } } @IgnoreExtraProperties public class TVSet { private String title; private String imageFile; //private Bitmap picture; public TVSet(){ } public TVSet(String title){ this.title = title; } public TVSet(Bitmap picture){ imageFile = compressImage(picture); } public void setTitle(String title){ this.title = title; } public String getTitle() { return title; } private String compressImage(Bitmap image){ ByteArrayOutputStream bYtE = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.PNG, 100, bYtE); //image.recycle(); byte[] byteArray = bYtE.toByteArray(); String imageFile = Base64.encodeToString(byteArray, Base64.DEFAULT); return imageFile; } @Exclude public Bitmap getImage() { byte[] decodedString = Base64.decode(imageFile, Base64.DEFAULT); Bitmap bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); return bitmap; } public String getImageFile(){ return imageFile; } } 

    Desculpe a má formatting. Qualquer ajuda é apreciada.

  • Firebase @PropertyName não funciona
  • Como recuperair um object da list da base de firefox no Android
  • Firebase Android: onDataChange () evento sempre executado no segmento de UI principal?
  • Por que recebo "Falha ao saltair paira digitair" quando eu giro o JSON da Firebase paira objects Java?
  • Como obter a key do valor na base de fogo
  • Como recuperair dados do database Firebase em order decrescente?
  • One Solution collect form web for “Google Firebase serializa / deserializa”

    tente usair

    Map<String, String> data= (HashMap<String, String>)dataSnapshot.getValue();

    ao invés de

    GenericTypeIndicator<List<Event>> t = new GenericTypeIndicator<List<Event>>() {}; List<Event> list = messageSnapshot.getValue(t);

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.