Commit Graph

12 Commits

Author SHA1 Message Date
Giovanni Bassi 6b24309fc9
Add .NET 7, 8, trimming and AOT support
Also fixed several nullability warnings.

Signed-off-by: Giovanni Bassi <giggio@giggio.net>
2023-11-13 15:49:46 -03:00
Jon Skeet d9e10ead4f Implement public JsonElement conversions in JsonEventFormatter
The method names are consistent with the ones in
ProtobufEventFormatter and the Json.NET event formatter.

Currently batch conversion is not supported, but we can add that later if requested.

The ConvertToJsonElement method is horribly inefficient at the
moment (serialize then parse); we can consider how to make it more
efficient later if necessary.

Signed-off-by: Jon Skeet <jonskeet@google.com>
2022-08-18 20:50:26 +01:00
Jon Skeet b67ac2b556 fix: Observe serialization options in JsonEventFormatter for System.Text.Json
Fixes #225

Signed-off-by: Jon Skeet <jonskeet@google.com>
2022-08-05 07:38:52 +01:00
Jon Skeet f74d383c18 fix: Use just the media type to detect JSON, not whole datacontenttype
Fixes #216

Signed-off-by: Jon Skeet <jonskeet@google.com>
2022-06-29 07:53:49 +01:00
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