• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JaCraig / SerialBox / 11905976443

19 Nov 2024 03:59AM UTC coverage: 69.118%. First build
11905976443

push

github

JaCraig
feat: Updating to .Net 8/9 and workflow updates

- Migrating to .Net 8/9 due to issues with new MS packages.
- Updating workflows.
- Updated code to take advantage of .Net 8+ constructs.

BREAKING CHANGE: Removing .Net 6/7 support as .Net 9 dependencies say they work with it in the package but then throw warnings. I don't know why this approach was taken but it breaks a bunch of automation.

47 of 88 branches covered (53.41%)

Branch coverage included in aggregate %.

94 of 115 new or added lines in 8 files covered. (81.74%)

94 of 116 relevant lines covered (81.03%)

5.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.67
/SerialBox/Default/JSONSerializer.cs
1
/*
2
Copyright 2016 James Craig
3

4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7

8
    http://www.apache.org/licenses/LICENSE-2.0
9

10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16

17
using SerialBox.BaseClasses;
18
using System;
19
using System.IO;
20
using System.Runtime.Serialization.Json;
21
using System.Text;
22
using System.Text.RegularExpressions;
23

24
namespace SerialBox.Default
25
{
26
    /// <summary>
27
    /// JSON Serializer
28
    /// </summary>
29
    /// <seealso cref="SerializerBase{String}"/>
30
    public class JSONSerializer : SerializerBase<string>
31
    {
32
        /// <summary>
33
        /// Content type (MIME type)
34
        /// </summary>
35
        public override string ContentType => "application/json";
11✔
36

37
        /// <summary>
38
        /// File type
39
        /// </summary>
40
        public override string FileType => ".json";
1✔
41

42
        /// <summary>
43
        /// Name
44
        /// </summary>
NEW
45
        public override string Name => "JSON";
×
46

47
        /// <summary>
48
        /// JSONP regex filter
49
        /// </summary>
50
        private static readonly Regex _JsonPRegex = new(@"[^\(]+\(([^\)]*)\);", RegexOptions.IgnoreCase);
1✔
51

52
        /// <summary>
53
        /// Deserializes the data
54
        /// </summary>
55
        /// <param name="objectType">Object type</param>
56
        /// <param name="data">Data to deserialize</param>
57
        /// <returns>The deserialized data</returns>
58
        public override object? Deserialize(Type objectType, string data)
59
        {
60
            if (string.IsNullOrEmpty(data) || objectType == null)
4!
NEW
61
                return null;
×
62
            data = _JsonPRegex.Replace(data, "$1");
4✔
63
            using var Stream = new MemoryStream(Encoding.UTF8.GetBytes(data));
4✔
64
            var Serializer = new DataContractJsonSerializer(objectType);
4✔
65
            return Serializer.ReadObject(Stream);
4✔
66
        }
4✔
67

68
        /// <summary>
69
        /// Serializes the object
70
        /// </summary>
71
        /// <param name="objectType">Object type</param>
72
        /// <param name="data">Data to serialize</param>
73
        /// <returns>The serialized data</returns>
74
        public override string? Serialize(Type objectType, object data)
75
        {
76
            if (data == null || objectType == null)
4!
NEW
77
                return null;
×
78
            var ReturnValue = "";
4✔
79
            using (var Stream = new MemoryStream())
4✔
80
            {
81
                var Serializer = new DataContractJsonSerializer(data.GetType());
4✔
82
                Serializer.WriteObject(Stream, data);
4✔
83
                Stream.Flush();
4✔
84
                var ResultingArray = Stream.ToArray();
4✔
85
                ReturnValue = Encoding.UTF8.GetString(ResultingArray, 0, ResultingArray.Length);
4✔
86
            }
4✔
87
            return ReturnValue;
4✔
88
        }
89
    }
90
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc