Commit Graph

8 Commits

Author SHA1 Message Date
Jon Skeet b1f29cf25b Support data content type inference
- New methods in CloudEventFormatter to support inference
- JsonEventFormatter infers a content type of application/json for non-binary data
- All transports use the inferred content type when formatting in binary mode
- Documentation for both formatters and bindings has been updated

Signed-off-by: Jon Skeet <jonskeet@google.com>
2022-02-25 07:11:13 +00:00
Jon Skeet c4a938c24c fix: Minor tweaks to the System.Text.Json JsonEventFormatter for compliance
- Make "JSON media type detection" configurable, and default to */json and */*+json
- Default to JSON content type (including making it present in the serialized event)
- Make a "binary vs non-binary" distinction as the first part of serialization (instead of as a fallback)
- Deserialize string data values regardless of content type
- Prohibit non-string data values for non-JSON content types

Signed-off-by: Jon Skeet <jonskeet@google.com>
2022-01-20 07:29:29 +00:00
Jon Skeet 4f13307d66 Update to .NET 6 SDK to build and netcoreapp3.1 for test
This requires a few nullable-reference-type overrides in tests where
we're absolutely confident they won't be null (and if we're wrong,
an NRE is fine to break the test).

Signed-off-by: Jon Skeet <jonskeet@google.com>
2022-01-12 07:09:02 +00:00
Jon Skeet e7ebdd7c1c Enable nullable reference types for unit test project
Signed-off-by: Jon Skeet <jonskeet@google.com>
2021-07-10 07:03:43 +01:00
Jon Skeet e772c1b110 Use ReadOnlyMemory<byte> in CloudEventFormatter
This sometimes feels a little cumbersome, with conversions that will
*sometimes* involve copying data, but leaves room for optimization
later and is a more flexible API in the long term.

Signed-off-by: Jon Skeet <jonskeet@google.com>
2021-06-05 22:13:07 +01:00
Jon Skeet 380fbfbfa7 Implement JsonEventFormatter<T> for System.Text.Json
Signed-off-by: Jon Skeet <jonskeet@google.com>
2021-05-11 20:41:10 +01:00
Jon Skeet f7f9bb1db5 test: Tests for batch event encoding/decoding
Signed-off-by: Jon Skeet <jonskeet@google.com>
2021-04-12 08:54:03 +01:00
Jon Skeet 93c49cad9f Implement JsonEventFormatter for System.Text.Json
This leads to two different formatters both called
JsonEventFormatter, just in different namespaces. That probably
wouldn't cause too much ambiguity, as few applications would depend
on both packages. It avoids longer names such as
"SystemTextJsonEventFormatter" which is pretty unwieldy.

Both the implementation and the tests are very much based on the
Newtonsoft.Json implementation.

Fixes #42.

Signed-off-by: Jon Skeet <jonskeet@google.com>
2021-03-24 07:22:41 +00:00