You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add CreateJson overloads to BinaryContent for simplified JSON serialization (#50921)
* Initial plan
* Add CreateJson overloads to BinaryContent
Co-authored-by: KrzysztofCwalina <9724236+KrzysztofCwalina@users.noreply.github.com>
* Add MediaType property to BinaryContent and consolidate tests
Co-authored-by: KrzysztofCwalina <9724236+KrzysztofCwalina@users.noreply.github.com>
* Remove JsonBinaryContent class and use regular Create method
Co-authored-by: KrzysztofCwalina <9724236+KrzysztofCwalina@users.noreply.github.com>
* Changes before error encountered
Co-authored-by: KrzysztofCwalina <9724236+KrzysztofCwalina@users.noreply.github.com>
* Add MediaType verification to CreateJson tests and address reviewer feedback
Co-authored-by: KrzysztofCwalina <9724236+KrzysztofCwalina@users.noreply.github.com>
* Update API surface files after adding CreateJson methods and MediaType property
Co-authored-by: KrzysztofCwalina <9724236+KrzysztofCwalina@users.noreply.github.com>
* Fix MediaType property for ModelBinaryContent when model is serialized as JSON
- Added logic to set MediaType to "application/json" when model will be serialized as JSON format
- This applies to both IPersistableModel and IJsonModel implementations that return "J" format
- Updated tests to verify MediaType is correctly set for model-based BinaryContent
- Addresses reviewer feedback about missing MediaType for JSON-serialized models
Co-authored-by: KrzysztofCwalina <9724236+KrzysztofCwalina@users.noreply.github.com>
* Add CreateJson(string) overload to BinaryContent for raw JSON strings
Co-authored-by: jsquire <913445+jsquire@users.noreply.github.com>
* Add optional validation parameter to CreateJson(string) overload
Co-authored-by: KrzysztofCwalina <9724236+KrzysztofCwalina@users.noreply.github.com>
* Add AOT compliance attributes to CreateJson methods to resolve CI warnings
Co-authored-by: KrzysztofCwalina <9724236+KrzysztofCwalina@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: KrzysztofCwalina <9724236+KrzysztofCwalina@users.noreply.github.com>
Co-authored-by: jsquire <913445+jsquire@users.noreply.github.com>
[System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation.")]
privateconststringJsonSerializerRequiresDynamicCode="JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation.";
24
+
privateconststringJsonSerializerRequiresUnreferencedCode="JSON serialization and deserialization might require types that cannot be statically analyzed.";
25
+
26
+
/// <summary>
27
+
/// Gets the media type of the content.
28
+
/// </summary>
29
+
publicstring?MediaType{get;protectedset;}
20
30
21
31
/// <summary>
22
32
/// Creates an instance of <see cref="BinaryContent"/> that contains the
@@ -65,6 +75,91 @@ public static BinaryContent Create(Stream stream)
65
75
returnnewStreamBinaryContent(stream);
66
76
}
67
77
78
+
/// <summary>
79
+
/// Creates an instance of <see cref="BinaryContent"/> that contains the
80
+
/// JSON representation of the provided object.
81
+
/// </summary>
82
+
/// <typeparam name="T">The type of the object to serialize.</typeparam>
83
+
/// <param name="jsonSerializable">The object to serialize to JSON.</param>
84
+
/// <param name="options">The <see cref="JsonSerializerOptions"/> to use for serialization.
85
+
/// If not provided, the default options will be used.</param>
86
+
/// <returns>An instance of <see cref="BinaryContent"/> that contains the
87
+
/// JSON representation of the provided object.</returns>
88
+
#pragma warning disable AZC0014// Avoid using banned types in public API
0 commit comments