Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/libraries/System.Text.Json/src/System.Text.Json.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<NoWarn>CS8969</NoWarn>
<IncludeInternalObsoleteAttribute>true</IncludeInternalObsoleteAttribute>
<IsPackable>true</IsPackable>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<ServicingVersion>5</ServicingVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<ServicingVersion>6</ServicingVersion>
<PackageDescription>Provides high-performance and low-allocating types that serialize objects to JavaScript Object Notation (JSON) text and deserialize JSON text to objects, with UTF-8 support built-in. Also provides types to read and write JSON text encoded as UTF-8, and to create an in-memory document object model (DOM), that is read-only, for random access of the JSON elements within a structured view of the data.

The System.Text.Json library is built-in as part of the shared framework in .NET Runtime. The package can be installed when you need to use it in other target frameworks.</PackageDescription>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,18 @@ public Func<IEnumerable<Tuple<TKey, TValue>>, TFSharpMap> CreateFSharpMapConstru
}

private Attribute? GetFSharpCompilationMappingAttribute(Type type)
=> type.GetCustomAttribute(_compilationMappingAttributeType, inherit: true);
{
object[] attributes = type.GetCustomAttributes(_compilationMappingAttributeType, inherit: false);
return attributes.Length == 0 ? null : (Attribute)attributes[0];
}

private SourceConstructFlags GetSourceConstructFlags(Attribute compilationMappingAttribute)
=> _sourceConstructFlagsGetter is null ? SourceConstructFlags.None : (SourceConstructFlags)_sourceConstructFlagsGetter.Invoke(compilationMappingAttribute, null)!;

// If the provided type is generated by the F# compiler, returns the runtime FSharp.Core assembly.
private static Assembly? GetFSharpCoreAssembly(Type type)
{
foreach (Attribute attr in type.GetCustomAttributes(inherit: true))
foreach (Attribute attr in type.GetCustomAttributes(inherit: false))
{
Type attributeType = attr.GetType();
if (attributeType.FullName == CompilationMappingAttributeTypeName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,22 @@ let ``Recursive struct records are supported``() =
Assert.Equal("""{"Next":[{"Next":[null]}]}""", json)
let deserializedValue = JsonSerializer.Deserialize<RecursiveStructRecord>(json)
Assert.Equal(value, deserializedValue)


[<JsonDerivedType(typeof<DerivedClass>, "derived")>]
type BaseClass(x : int) =
member _.X = x

and DerivedClass(x : int, y : bool) =
inherit BaseClass(x)
member _.Y = y

[<Fact>]
let ``Support F# class hierarchies`` () =
let value = DerivedClass(42, true) :> BaseClass
let json = JsonSerializer.Serialize(value)
Assert.Equal("""{"$type":"derived","Y":true,"X":42}""", json)
let deserializedValue = JsonSerializer.Deserialize<BaseClass>(json)
let derived = Assert.IsType<DerivedClass>(deserializedValue)
Assert.Equal(42, deserializedValue.X)
Assert.Equal(true, derived.Y)
Loading