Kanagalingam
Kanagalingam

Reputation: 2204

How to pass hashmap values to model class constructor in java

I am learning android and I want to show the values from firebase Db into a recyclerview in my app.

I have a pojo class like,

enter image description here

And I got the iteration value from firebase like shown in below picture.

You can see that each entity of my model class is coming as a Hashmap key.

How should i iterate through this, so that i can pass the values to my model class constructor and thereby add the model class to my recyclerview adapter list.

. . . .

enter image description here

Upvotes: 0

Views: 762

Answers (2)

rzwitserloot
rzwitserloot

Reputation: 103254

You need a so-called 'marshalling' library which turns JSON into java POJOs.

The commonly used libraries are jackson and GSON ... for normal java. For android? Possibly something is baked in. Perhaps GSON, which is authored by google.

Upvotes: 2

peshkira
peshkira

Reputation: 6239

If your HashMap is always with the size of 3 and you know the key names, then you can just do the following.

UserInfo info = new UserInfo(map.get("referralName"), map.get("referralContact"), map.get("referralType"));

Upvotes: 2

Related Questions