Skip to content
Prev Previous commit
Next Next commit
Add missing access modifiers to class properties
Add note about immutable types
  • Loading branch information
jozkee committed Dec 3, 2019
commit e12a8f6d0a0bcca83a9414b5849f2d4e3f3515a3
18 changes: 9 additions & 9 deletions src/libraries/System.Text.Json/docs/ReferenceHandling_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ Having the following class:
```cs
class Employee
{
string Name { get; set; }
Employee Manager { get; set; }
List<Employee> Subordinates { get; set; }
public string Name { get; set; }
public Employee Manager { get; set; }
public List<Employee> Subordinates { get; set; }
}
```

Expand Down Expand Up @@ -598,17 +598,17 @@ public static void TestDictionary_Collision()


## Immutable types
Since these types are created with the help of an internal converter, and they are not parsed until the entire block of JSON finishes, nested reference to these types is impossible to identify, unless you re-scan the resulting object, which is too expensive.
Since these types are created with the help of an internal converter, and they are not parsed until the entire block of JSON finishes; nested reference to these types is impossible to identify, unless you re-scan the resulting object, which is too expensive.

With that said, the deserializer will throw when it reads `$id` on any of these types.
With that said, the deserializer will throw when it reads `$id` on any of these types; but regardless of that, when writing those types, they are going to be preserved as any other collection type (`{ "$id": "1", "$values": [...] }`) since those types can still being parsed into a collection type that it is supported.

* **Immutable types**: i.e: `ImmutableList` and `ImmutableDictionary`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* **Immutable types**: i.e: `ImmutableList` and `ImmutableDictionary`
* **Immutable types**: e.g. `ImmutableList` and `ImmutableDictionary`

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always though i.e. stands for "in example".

* **System.Array**

## Value types

* **Serialization**:
The serializer emits an `$id` for every JSON complex type, that means that if you have a custom struct, the serializer will append an id to it, however, there will never be a reference to these ids, since by default it uses `ReferenceEquals` when checking for references.
The serializer emits an `$id` for every JSON complex type, that means that if you have a custom struct (which is value type), the serializer will append an `$id` to it, however, there will never be a reference to those `$id`s, since by default it uses `ReferenceEquals` when comparing the objects.

```cs
public static void SerializeStructs()
Expand Down Expand Up @@ -733,12 +733,12 @@ Things that may build on top based on customer feedback:
// Example of a class annotated with JsonReferenceHandling attributes.
[JsonReferenceHandling(ReferenceHandling.Preserve)]
public class Employee {
string Name { get; set; }
public string Name { get; set; }

[JsonReferenceHandling(ReferenceHandling.Ignore)]
Employee Manager { get; set; }
public Employee Manager { get; set; }

List<Employee> Subordinates { get; set; }
public List<Employee> Subordinates { get; set; }
}
```

Expand Down