the NullPointerException
happens because when you build your Customer
you call fDoc.content()
but fDoc
is null.
What you can do is:
public Customer findCustomerDocId(String docId) throws NullPointerException{
Gson gson = new GsonBuilder().create();
JsonDocument fDoc = theBucket.get(docId);
if (fDoc == null) {
//create the content. JSON String?
String newContent;
//create the doc and store
RawJsonDocument newDoc = RawJsonDocument.create(docId, newContent);
theBucket.insert(newDoc);
//you should have also a Customer object at this point, to return
return ???;
} else {
Customer cust = gson.fromJson(fDoc.content().toString(), Customer.class);
return cust;
}
}