This is my json
{
"profile_min_salary": 10000,
"profile_requirement_checklist": "Excel Aana Chahiye.",
"tags": "central,12th pass,thoda english,good english,fluent
english,male,fresher,female"
}
Here is my Model
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY,
getterVisibility = JsonAutoDetect.Visibility.NONE,
setterVisibility = JsonAutoDetect.Visibility.NONE)
@JsonIgnoreProperties(ignoreUnknown = true)'
public class Job {
@JsonProperty("profile_min_salary")
private Integer profileMinSalary;
@JsonProperty("profile_requirement_checklist")
private String profileRequirementChecklist;
@JsonProperty("tags")
private String tags;
public String getTags() {
return tags;
}
public Integer getProfileMinSalary() {
return profileMinSalary;
}
public void setProfileMinSalary(Integer profileMinSalary) {
this.profileMinSalary = profileMinSalary;
}
public void setTags(String tags) {
this.tags = tags;
}
public String getProfileRequirementChecklist() {
return profileRequirementChecklist;
}
public void setProfileRequirementChecklist(String profileRequirementChecklist) {
this.profileRequirementChecklist = profileRequirementChecklist;
}
}
This is my firebase code snippet
@Override
public void onChildAdded(final DataSnapshot dataSnapshot, String previousChildName) {
new Thread(new Runnable() {
@Override
public void run() {
try {
Job job = dataSnapshot.getValue(Job.class);
doOperationOnJob(job);
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
Crashlytics.logException(e);
}
}
}).start();
}
But my class is getting only tags parameter else are null why ??
While if I am writing this way it is working fine
@Override
public void onChildAdded(final DataSnapshot dataSnapshot, String previousChildName) {
new Thread(new Runnable() {
@Override
public void run() {
try {
String jsonData = new ObjectMapper().writeValueAsString(dataSnapshot.getValue());
Job job= new ObjectMapper().readValue(jsonData , Job.class);
doOperationOnJob(job);
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
Crashlytics.logException(e);
}
}
}).start();
}
What should i change in code to make it work in first scenario ?? I am stuck.