Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion skills/cosmosdb-best-practices/rules/model-json-serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Handle JSON serialization correctly for Cosmos DB documents
impact: HIGH
impactDescription: prevents data loss, null constructor errors, and serialization failures
tags: model, serialization, json, jackson, jsonignore, jsonproperty, bigdecimal
tags: model, serialization, json, jackson, jsonignore, jsonproperty, bigdecimal, jsonignoreproperties, change-feed
---

## Handle JSON Serialization Correctly for Cosmos DB
Expand Down Expand Up @@ -139,4 +139,36 @@ private Set<String> authorities;

Convert between simple and complex types in the service layer, not in the entity.

**Rule 5: Always add `@JsonIgnoreProperties(ignoreUnknown = true)` to entity classes**

Cosmos DB documents contain system metadata fields (`_rid`, `_self`, `_etag`, `_ts`, `_lsn`) that are not part of your entity model. Without this annotation, Jackson throws `UnrecognizedPropertyException` when deserializing documents — especially during Change Feed processing where these fields are always present:

```
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:
Unrecognized field "_lsn" (class PlayerProfile), not marked as ignorable
```

```java
// ❌ Fails on system metadata fields from Cosmos DB
@Container(containerName = "players")
public class PlayerProfile {
@Id
private String id;
private String playerId;
private int score;
}

// ✅ Ignores unknown fields — safe for Cosmos DB system metadata
@JsonIgnoreProperties(ignoreUnknown = true)
@Container(containerName = "players")
public class PlayerProfile {
@Id
private String id;
private String playerId;
private int score;
}
```

This is critical for Change Feed consumers where system metadata fields are always included in the document payload.

Reference: [Jackson annotations guide](https://github.com/FasterXML/jackson-annotations/wiki/Jackson-Annotations)
2 changes: 1 addition & 1 deletion testing-v2/harness/conftest_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def cosmos_client():
@pytest.fixture(scope="session")
def cosmos_database(cosmos_client, iteration_config):
"""The Cosmos DB database used by the app."""
db_name = iteration_config.get("database", "gaming-leaderboard-db")
db_name = iteration_config.get("database", "test-db")
return cosmos_client.get_database_client(db_name)


Expand Down
21 changes: 21 additions & 0 deletions testing-v2/scenarios/ai-chat-rag/iterations/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Build artifacts (per-language)
__pycache__/
*.pyc
*.pyo
node_modules/
bin/
obj/
target/
.gradle/
build/
dist/
*.egg-info/
venv/
.venv/

# Runtime logs and temp files
app-output.log
app-error.log
_start-app.cmd
build-output.log
build-error.log
21 changes: 21 additions & 0 deletions testing-v2/scenarios/ecommerce-order-api/iterations/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Build artifacts (per-language)
__pycache__/
*.pyc
*.pyo
node_modules/
bin/
obj/
target/
.gradle/
build/
dist/
*.egg-info/
venv/
.venv/

# Runtime logs and temp files
app-output.log
app-error.log
_start-app.cmd
build-output.log
build-error.log
21 changes: 21 additions & 0 deletions testing-v2/scenarios/gaming-leaderboard/iterations/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Build artifacts (per-language)
__pycache__/
*.pyc
*.pyo
node_modules/
bin/
obj/
target/
.gradle/
build/
dist/
*.egg-info/
venv/
.venv/

# Runtime logs and temp files
app-output.log
app-error.log
_start-app.cmd
build-output.log
build-error.log
21 changes: 21 additions & 0 deletions testing-v2/scenarios/iot-device-telemetry/iterations/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Build artifacts (per-language)
__pycache__/
*.pyc
*.pyo
node_modules/
bin/
obj/
target/
.gradle/
build/
dist/
*.egg-info/
venv/
.venv/

# Runtime logs and temp files
app-output.log
app-error.log
_start-app.cmd
build-output.log
build-error.log
21 changes: 21 additions & 0 deletions testing-v2/scenarios/multitenant-saas/iterations/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Build artifacts (per-language)
__pycache__/
*.pyc
*.pyo
node_modules/
bin/
obj/
target/
.gradle/
build/
dist/
*.egg-info/
venv/
.venv/

# Runtime logs and temp files
app-output.log
app-error.log
_start-app.cmd
build-output.log
build-error.log
Loading