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

JaCraig / Mecha / 18535499073

15 Oct 2025 04:17PM UTC coverage: 81.885% (-0.08%) from 81.963%
18535499073

push

github

web-flow
Merge pull request #359 from JaCraig/dependabot/nuget/Mecha.Core/dependencies-598abd322d

fix: Bump the dependencies group with 2 updates

757 of 1060 branches covered (71.42%)

Branch coverage included in aggregate %.

1345 of 1507 relevant lines covered (89.25%)

6643763.25 hits per line

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

92.86
/Mecha.Core/Datasources/Defaults/DefaultSerializer.cs
1
/*
2
Copyright 2021 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 Mecha.Core.Datasources.Interfaces;
18
using Mecha.Core.ExtensionMethods;
19
using System;
20
using System.Text.Json;
21

22
namespace Mecha.Core.Datasources.Defaults
23
{
24
    /// <summary>
25
    /// Default serializer (goes to JSON)
26
    /// </summary>
27
    /// <seealso cref="ISerializer"/>
28
    public class DefaultSerializer : ISerializer
29
    {
30
        /// <summary>
31
        /// Deserializes the specified data.
32
        /// </summary>
33
        /// <param name="objectType">Type of the object.</param>
34
        /// <param name="data">The data.</param>
35
        /// <returns>The deserialized value.</returns>
36
        public object? Deserialize(Type objectType, string? data)
37
        {
38
            if (string.IsNullOrWhiteSpace(data))
8✔
39
                return null;
6✔
40
            try
41
            {
42
                return JsonSerializer.Deserialize(data, objectType);
2✔
43
            }
44
            catch { return null; }
×
45
        }
2✔
46

47
        /// <summary>
48
        /// Serializes the specified data.
49
        /// </summary>
50
        /// <param name="objectType">Type of the object.</param>
51
        /// <param name="data">The data.</param>
52
        /// <returns>The serialized value used for storage.</returns>
53
        public string? Serialize(Type objectType, object? data)
54
        {
55
            if (data.IsInfinite())
30✔
56
                data = 0;
4✔
57
            try
58
            {
59
                return JsonSerializer.Serialize(data, objectType);
30✔
60
            }
61
            catch { return ""; }
12✔
62
        }
30✔
63
    }
64
}
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