Skip to content
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

Support customized reading and writing of JSON values #31021

Merged
merged 3 commits into from
Jun 13, 2023

Conversation

ajcvickers
Copy link
Contributor

Part of #30730

  • Type mappings now have a JsonValueReaderWriter that handles reading and writing JSON for the type.
  • This can be overridden by a JsonValueReaderWriter on a property, for example, to allow GeoJson to be written instead of WKT.
  • These are typically singleton instances, and can be optimized out for well-known cases.
  • If the type mapping has a converter, then the converter must be applied to the value before being written to JSON, and the converter must be applied after reading the JSON value.
  • If the property itself has a JsonValueReaderWriter, then the unconverted property value is passed to this reader/writer.

@ajcvickers ajcvickers requested a review from a team June 2, 2023 13:08
@ajcvickers
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).


/// <inheritdoc />
public override byte[] FromJsonTyped(ref Utf8JsonReaderManager manager)
=> manager.CurrentReader.GetBytesFromBase64();
Copy link
Member

Choose a reason for hiding this comment

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

Did we decide to also accept number arrays?

/// <inheritdoc />
public virtual JsonValueReaderWriter? FindReaderWriter(Type type)
{
if (type == typeof(int))
Copy link
Member

Choose a reason for hiding this comment

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

@roji I don't think this will appear on a hot path, but can you think of a faster way of implementing this?

@AndriySvyryd
Copy link
Member

Part of #30604

Part of #30730

- Type mappings now have a `JsonValueReaderWriter` that handles reading and writing JSON for the type.
- This can be overridden by a `JsonValueReaderWriter` on a property, for example, to allow GeoJson to be written instead of WKT.
- These are typically singleton instances, and can be optimized out for well-known cases.
- If the type mapping has a converter, then the converter must be applied to the value before being written to JSON, and the converter must be applied after reading the JSON value.
- If the property itself has a `JsonValueReaderWriter`, then the unconverted property value is passed to this reader/writer.
@ajcvickers ajcvickers force-pushed the 230523_JsonAndTheElementalists branch from e31db4d to 3c27726 Compare June 12, 2023 17:31
@ajcvickers ajcvickers merged commit b336fbe into main Jun 13, 2023
@ajcvickers ajcvickers deleted the 230523_JsonAndTheElementalists branch June 13, 2023 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants