Skip to content

Commit

Permalink
switch back to require type to be IdentifiedObject
Browse files Browse the repository at this point in the history
  • Loading branch information
runeanielsen committed Oct 8, 2024
1 parent 1ff6f64 commit 23efa1a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/CIM.Cson/CsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ public class CsonSerializer
/// <summary>
/// Serializes a single object to a JSON string
/// </summary>
public string SerializeObject<T>(T obj) => _serializer.Serialize(obj);
public string SerializeObject(IdentifiedObject obj) => _serializer.Serialize(obj);

/// <summary>
/// Deserializes a single object into its <see cref="IdentifiedObject"/> subclass
/// </summary>
public T DeserializeObject<T>(string json)
public IdentifiedObject DeserializeObject(string json)
{
var obj = _serializer.Deserialize(json);

try
{
return (T)obj;
return (IdentifiedObject)obj;
}
catch (Exception exception)
{
Expand All @@ -46,7 +46,7 @@ public T DeserializeObject<T>(string json)
/// <summary>
/// Returns a JSONL stream from the given <paramref name="objects"/>
/// </summary>
public Stream SerializeObjects<T>(IEnumerable<T> objects)
public Stream SerializeObjects(IEnumerable<IdentifiedObject> objects)
{
var enumerator = objects.GetEnumerator();

Expand Down Expand Up @@ -81,7 +81,7 @@ public Stream SerializeObjects<T>(IEnumerable<T> objects)
/// <summary>
/// Deserializes the given JSON stream and returns <see cref="IdentifiedObject"/> while traversing it
/// </summary>
public IEnumerable<T> DeserializeObjects<T>(Stream source)
public IEnumerable<IdentifiedObject> DeserializeObjects(Stream source)
{
var lineCounter = 0;

Expand All @@ -95,18 +95,18 @@ public IEnumerable<T> DeserializeObjects<T>(Stream source)

if (string.IsNullOrWhiteSpace(line)) continue;

var obj = DeserializeObjectFromLine<T>(line, lineCounter);
var obj = DeserializeObjectFromLine(line, lineCounter);

yield return obj;
}
}
}

T DeserializeObjectFromLine<T>(string line, int lineCounter)
IdentifiedObject DeserializeObjectFromLine(string line, int lineCounter)
{
try
{
return DeserializeObject<T>(line);
return DeserializeObject(line);
}
catch (Exception exception)
{
Expand Down

0 comments on commit 23efa1a

Please sign in to comment.