Skip to content

Commit e5d02c5

Browse files
committed
switch order of testing and JSON serialization
1 parent ad40788 commit e5d02c5

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

Diff for: aspnetcore/tutorials/first-mongo-app.md

+27-27
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,33 @@ The preceding web API controller:
263263
* Contains action methods to support GET, POST, PUT, and DELETE HTTP requests.
264264
* Calls <xref:Microsoft.AspNetCore.Mvc.ControllerBase.CreatedAtAction%2A> in the `Create` action method to return an [HTTP 201](https://www.rfc-editor.org/rfc/rfc9110#status.201) response. Status code 201 is the standard response for an HTTP POST method that creates a new resource on the server. `CreatedAtAction` also adds a `Location` header to the response. The `Location` header specifies the URI of the newly created book.
265265

266+
## Configure JSON serialization options
267+
268+
There are two details to change about the JSON responses returned in the [Test the web API](#test-the-web-api) section:
269+
270+
* The property names' default camel casing should be changed to match the Pascal casing of the CLR object's property names.
271+
* The `bookName` property should be returned as `Name`.
272+
273+
To satisfy the preceding requirements, make the following changes:
274+
275+
1. In `Program.cs`, chain the following highlighted code on to the `AddControllers` method call:
276+
277+
:::code language="csharp" source="first-mongo-app/samples/9.x/BookStoreApi/Program.cs" id="snippet_AddControllers" highlight="10-11":::
278+
279+
With the preceding change, property names in the web API's serialized JSON response match their corresponding property names in the CLR object type. For example, the `Book` class's `Author` property serializes as `Author` instead of `author`.
280+
281+
1. In `Models/Book.cs`, annotate the `BookName` property with the [`[JsonPropertyName]`](xref:System.Text.Json.Serialization.JsonPropertyNameAttribute) attribute:
282+
283+
:::code language="csharp" source="first-mongo-app/samples/9.x/BookStoreApi/Models/Book.cs" id="snippet_BookName" highlight="2":::
284+
285+
The `[JsonPropertyName]` attribute's value of `Name` represents the property name in the web API's serialized JSON response.
286+
287+
1. Add the following code to the top of `Models/Book.cs` to resolve the `[JsonProperty]` attribute reference:
288+
289+
:::code language="csharp" source="first-mongo-app/samples/9.x/BookStoreApi/Models/Book.cs" id="snippet_UsingSystemTextJsonSerialization":::
290+
291+
1. Repeat the steps defined in the [Test the web API](#test-the-web-api) section. Notice the difference in JSON property names.
292+
266293
## Test the web API
267294

268295
# [Visual Studio](#tab/visual-studio)
@@ -494,33 +521,6 @@ The OpenAPI specification is a document in JSON format that describes the struct
494521
1. The response should have a status code of 204 (No Content), indicating that the book was successfully deleted.
495522
---
496523

497-
## Configure JSON serialization options
498-
499-
There are two details to change about the JSON responses returned in the [Test the web API](#test-the-web-api) section:
500-
501-
* The property names' default camel casing should be changed to match the Pascal casing of the CLR object's property names.
502-
* The `bookName` property should be returned as `Name`.
503-
504-
To satisfy the preceding requirements, make the following changes:
505-
506-
1. In `Program.cs`, chain the following highlighted code on to the `AddControllers` method call:
507-
508-
:::code language="csharp" source="first-mongo-app/samples/9.x/BookStoreApi/Program.cs" id="snippet_AddControllers" highlight="10-11":::
509-
510-
With the preceding change, property names in the web API's serialized JSON response match their corresponding property names in the CLR object type. For example, the `Book` class's `Author` property serializes as `Author` instead of `author`.
511-
512-
1. In `Models/Book.cs`, annotate the `BookName` property with the [`[JsonPropertyName]`](xref:System.Text.Json.Serialization.JsonPropertyNameAttribute) attribute:
513-
514-
:::code language="csharp" source="first-mongo-app/samples/9.x/BookStoreApi/Models/Book.cs" id="snippet_BookName" highlight="2":::
515-
516-
The `[JsonPropertyName]` attribute's value of `Name` represents the property name in the web API's serialized JSON response.
517-
518-
1. Add the following code to the top of `Models/Book.cs` to resolve the `[JsonProperty]` attribute reference:
519-
520-
:::code language="csharp" source="first-mongo-app/samples/9.x/BookStoreApi/Models/Book.cs" id="snippet_UsingSystemTextJsonSerialization":::
521-
522-
1. Repeat the steps defined in the [Test the web API](#test-the-web-api) section. Notice the difference in JSON property names.
523-
524524
## Add authentication support to a web API
525525

526526
[!INCLUDE[](~/includes/DuendeIdentityServer.md)]

0 commit comments

Comments
 (0)