I am trying to run a Get method in java Restful API. I have tried naming my model classes similar to my real-time firebase that wasn't the issue.
This is my real-time firebase. reference is Devices/Lamp/Ambient
Here is my model class
private String LightSwitch;
private String DoorSwitch;
// empty COnstructor
public DeviceTest() { }
public DeviceTest(String lightSwitch, String doorSwitch) {
LightSwitch = lightSwitch;
DoorSwitch = doorSwitch;
}
public String getLightSwitch() {
return LightSwitch;
}
public void setLightSwitch(String lightSwitch) {
LightSwitch = lightSwitch;
}
public String getDoorSwitch() {
return DoorSwitch;
}
public void setDoorSwitch(String doorSwitch) {
DoorSwitch = doorSwitch;
}
}
Here is my readFirebase Method
public static List<DeviceTest> handleLight() {
FireBaseService fbs = null;
fbs = new FireBaseService();
device = new DeviceTest();
mylist = new ArrayList<>();
DatabaseReference ref = fbs.getDb()
.getReference("/Devices/Lamp");
ref.child("Ambient")
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
device = dataSnapshot.getValue(DeviceTest.class);
mylist = new ArrayList<>();
for (DataSnapshot unit : dataSnapshot.getChildren()) {
DeviceTest value = unit.getValue(DeviceTest.class);
mylist.add(value);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
//mylist.add(device);
return mylist;
}
Here is the GET method
@Path("/devices")
public class DeviceResource {
DeviceService deviceService = new DeviceService();
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<DeviceTest> getCustomers(){
return FireBaseService.handleLight();
}