Azure / Azure/azure-documentdb-java
Update using PoJo setters result in a "NullPointerException"
- Vorherrschende Sprache
- Java
- Sterne
- 51
- Forks
- 52
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Hi
the [todo tutorial](https://azure.microsoft.com/en-us/documentation/articles/documentdb-java-application/#UseService) show an "updateTodo" sample with the following comment:
```
// You can update the document as a JSON document directly.
// For more complex operations - you could de-serialize the document in
// to a POJO, update the POJO, and then re-serialize the POJO back in to
// a document.
```
I want to update my pojo using the java object (not the documentdb "Document" setters)
When I do that,
```
Document myDoc = getDocumentById(myId);
// De-serialize the document in to a TodoItem.
MyObject my = gson.fromJson(myDoc .toString(), MyObject.class);
LOG.debug("update object {}", my);
my.setName("IWantToUsePojoPlease");
Document updDocument = new Document(gson.toJson(my));
updDocument.setResourceId(myDoc.getResourceId());
updDocument.setId(myDoc.getId());
updDocument.set("entityType", ENTITY_TYPE);
try {
// Persist/replace the updated document.
updDocument = getDC().replaceDocument(updDocument, null).getResource();
```
I got the following error:
```
java.lang.NullPointerException
at com.microsoft.azure.documentdb.DocumentClient.trimBeginingAndEndingSlashes(DocumentClient.java:2160)
at com.microsoft.azure.documentdb.DocumentClient.joinPath(DocumentClient.java:2148)
at com.microsoft.azure.documentdb.DocumentClient.replaceDocument(DocumentClient.java:503)
```
I think this is a bug. Maybe the new Document instance loose the "_self"(SELF_LINK) reference and that's why the replace doesn't work. How could we keep this link ? Is it possible to fix this issue and add a second update sample using PoJo ?
If possible, I would like to avoid an update that will use Document.set(FIELD,VALUE) method but use PoJo (business) setters.
Regards
Beitragsleitfaden
Rechercherichtung
Beginne mit DocumentClient.replaceDocument und den Stack-Trace-Positionen DocumentClient.java:2148 und :2160. Vergleiche anschließend das ursprüngliche Document mit dem neuen Document, das aus dem POJO erstellt wurde. Prüfe das updateTodo-Beispiel im todo-Tutorial und ermittle, wie das Ersetzen auf POJO-Basis die erforderliche Dokumentreferenz bewahren sollte. Als erledigt gilt die Aufgabe, wenn das Update keine gemeldete NullPointerException mehr auslöst und das Beispiel den unterstützten Workflow erklärt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java
- Bereich
- databases
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100