-
Notifications
You must be signed in to change notification settings - Fork 3.6k
JSON Documentation #8882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
JSON Documentation #8882
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# JSON | ||
The ABP Framework provides an abstraction to work with JSON. Having such an abstraction has some benefits; | ||
|
||
* You can write library independent code. Therefore, you can change the underlying library with the minimum effort and code change. | ||
* You can easily change the underlying JSON library (System.Text.Json, Newtonsoft.Json, etc.) by configuring the options. | ||
* You can use the predefined converters defined in the ABP without worrying about the underlying library's internal details. | ||
|
||
> The JSON serialization system is implemented with the [Volo.Abp.Json](https://www.nuget.org/packages/Volo.Abp.Json) NuGet package. Most of the time, you don't need to manually [install it](https://abp.io/package-detail/Volo.Abp.Json) since it comes pre-installed with the [application startup template](Startup-Templates/Application.md). | ||
|
||
## IJsonSerializer | ||
|
||
You can inject `IJsonSerializer` and use it for JSON operations. Here is the available operations in the `IJsonSerializer` interface. | ||
|
||
```csharp | ||
public interface IJsonSerializer | ||
{ | ||
string Serialize(object obj, bool camelCase = true, bool indented = false); | ||
T Deserialize<T>(string jsonString, bool camelCase = true); | ||
object Deserialize(Type type, string jsonString, bool camelCase = true); | ||
} | ||
``` | ||
Usage Example: | ||
|
||
```csharp | ||
public class ProductManager | ||
{ | ||
public IJsonSerializer JsonSerializer { get; } | ||
|
||
public ProductManager(IJsonSerializer jsonSerializer) | ||
{ | ||
JsonSerializer = jsonSerializer; | ||
} | ||
|
||
public void SendRequest(Product product) | ||
{ | ||
var json= JsonSerializer.Serialize(product); | ||
// Left blank intentionally for demo purposes... | ||
} | ||
} | ||
``` | ||
|
||
## Configuration | ||
|
||
`AbpJsonOptions` type provides options for the JSON operations in the ABP Framework. | ||
|
||
Properties: | ||
* **DefaultDateTimeFormat(`string`)**: Default `DateTime` format. | ||
* **UseHybridSerializer(`bool`)**: True by default. Boolean field indicating whether the ABP Framework uses the hybrid approach or not. If the field is true, it will try to use `System.Json.Text` to handle JSON if it can otherwise use the `Newtonsoft.Json.` | ||
* **Providers(`ITypeList<IJsonSerializerProvider>`)**: List of JSON serializer providers implementing the `IJsonSerializerProvider` interface. You can create and add custom serializers to the list, and the ABP Framework uses them automatically. When the `Serialize` or `Deserialize` method is called on the `IJsonSerializer` interface, the ABP Framework calls the `CanHandle` methods of the given providers in reverse order and uses the first provider that returns `true` to do the JSON operation. | ||
|
||
ilkayilknur marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -320,6 +320,10 @@ | |
} | ||
] | ||
}, | ||
{ | ||
"text": "JSON", | ||
"path": "JSON.md" | ||
}, | ||
{ | ||
"text": "Features", | ||
"path": "Features.md" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.