Expected map on deserialization, but got java.lang.Long class

I get this error "Expected card on deserialization, but got java.lang.Long class" while I am using firebase database. I raised a question about the same problem in stackoverflow, but did not find a suitable solution.

This is my POJO class for storing data from firebase.

public class News { public String topic; public String detail; public String user; public Map<String, String> timestamp = null; public News(){ } public News(String topic, String detail, String user, HashMap<String, String> timeStamp){ this.topic = topic; this.detail = detail; this.user = user; this.timestamp = timeStamp; //this.timestamp.put("timestamp", timeStamp); //this.timestamp.put("timestamp", ServerValue.TIMESTAMP); } public String getTopic(){ return topic; } public String getDetail(){ return detail; } @Exclude public Map<String, Object> toMap() { HashMap<String, Object> result = new HashMap<>(); result.put("topic", topic); result.put("detail", detail); result.put("user", user); result.put("timestamp", timestamp); return result; } } 

And this is the main class in which I receive data from firebase.

 public class News_M extends AppCompatActivity { FirebaseListAdapter mAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_news); ListView messagesView = (ListView) findViewById(R.id.listview); DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("abc").child("news"); //News msg = new News("Holiday", "28 October", "fayeed", ServerValue.TIMESTAMP); //ref.push().setValue(msg); mAdapter = new FirebaseListAdapter<News>(this, News.class, android.R.layout.two_line_list_item, ref) { @Override protected void populateView(View view, News newsMessage, int position) { ((TextView)view.findViewById(android.R.id.text1)).setText(newsMessage.getTopic()); ((TextView)view.findViewById(android.R.id.text2)).setText(newsMessage.getDetail( )); } }; messagesView.setAdapter(mAdapter); } @Override protected void onDestroy() { super.onDestroy(); mAdapter.cleanup(); } } 
+5
source share

Source: https://habr.com/ru/post/1258586/


All Articles