<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Panagiotis Foutros on Medium]]></title>
        <description><![CDATA[Stories by Panagiotis Foutros on Medium]]></description>
        <link>https://medium.com/@g1otis.dev?source=rss-8930671f2ab1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*qXzlfU8PfAIGniCX.jpg</url>
            <title>Stories by Panagiotis Foutros on Medium</title>
            <link>https://medium.com/@g1otis.dev?source=rss-8930671f2ab1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 11:35:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@g1otis.dev/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[.NET Web API Application Development Using ChatGPT]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@g1otis.dev/net-web-api-application-development-using-chatgpt-part-2-unit-testing-ea7b562e989a?source=rss-8930671f2ab1------2"><img src="https://cdn-images-1.medium.com/max/2600/0*vIq-aDWzmJP-YNr_" width="5456"></a></p><p class="medium-feed-snippet">Part 2 Unit Testing</p><p class="medium-feed-link"><a href="https://medium.com/@g1otis.dev/net-web-api-application-development-using-chatgpt-part-2-unit-testing-ea7b562e989a?source=rss-8930671f2ab1------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@g1otis.dev/net-web-api-application-development-using-chatgpt-part-2-unit-testing-ea7b562e989a?source=rss-8930671f2ab1------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea7b562e989a</guid>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[generative-ai-tools]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[chatgpt]]></category>
            <dc:creator><![CDATA[Panagiotis Foutros]]></dc:creator>
            <pubDate>Sun, 02 Nov 2025 12:44:59 GMT</pubDate>
            <atom:updated>2025-12-18T09:11:21.910Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[.NET Web API Application Development Using ChatGPT]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@g1otis.dev/net-web-api-application-development-using-chatgpt-415625f322f5?source=rss-8930671f2ab1------2"><img src="https://cdn-images-1.medium.com/max/2600/0*5feS8BgE-Etlidep" width="3840"></a></p><p class="medium-feed-snippet">Part 1 Scaffolding</p><p class="medium-feed-link"><a href="https://medium.com/@g1otis.dev/net-web-api-application-development-using-chatgpt-415625f322f5?source=rss-8930671f2ab1------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@g1otis.dev/net-web-api-application-development-using-chatgpt-415625f322f5?source=rss-8930671f2ab1------2</link>
            <guid isPermaLink="false">https://medium.com/p/415625f322f5</guid>
            <category><![CDATA[poc]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[web-api-development]]></category>
            <dc:creator><![CDATA[Panagiotis Foutros]]></dc:creator>
            <pubDate>Sun, 12 May 2024 18:06:15 GMT</pubDate>
            <atom:updated>2025-12-18T09:10:46.939Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[C# Interface JSON Serialization and Deserialization]]></title>
            <link>https://medium.com/@g1otis.dev/c-interface-json-serialization-and-deserialization-930d60db638f?source=rss-8930671f2ab1------2</link>
            <guid isPermaLink="false">https://medium.com/p/930d60db638f</guid>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[newtonsoft]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[json]]></category>
            <dc:creator><![CDATA[Panagiotis Foutros]]></dc:creator>
            <pubDate>Wed, 26 Jan 2022 20:16:43 GMT</pubDate>
            <atom:updated>2024-05-06T14:22:49.514Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>C# Interface JSON Serialization and Deserialization using Newtonsoft</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kV5I0s7gUug1jnnV" /><figcaption>Photo by <a href="https://unsplash.com/@waldemarbrandt67w?utm_source=medium&amp;utm_medium=referral">Waldemar Brandt</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote><em>Created by Panagiotis Foutros</em></blockquote><h3>The problem</h3><p>Serialize an interface that may contain other interfaces as members and then deserialize it using a concrete type</p><p>It might not be a day to day work but is quite useful in case that you are facing the relevant problem.</p><p>As you can see we define below the <strong>Person Domain</strong> project that contains the models (interfaces) that will be implemented by other projects that depends on them.</p><h3>Person Domain Project:</h3><h4>Person’s Domain Project Interface 1</h4><pre>namespace Persons.Domain.Models <br>{<br>    public interface IPersonModel <br>    {<br>        string Name { get; set; }<br>        IWalkingStyle WalkingStyle { get; set; }<br>    }<br>}</pre><h4>Person’s Domain Project Interface 2</h4><pre>namespace Persons.Domain.Models {<br>	public interface IWalkingStyle {<br>		string WalkingType { get; set; }<br>		int SpeedKMPH { get; set; }<br>	}<br>}</pre><h3>Implementation #1: Person Database Project:</h3><h4>Person’s Database Project Implementation</h4><pre>namespace Persons.Database.Models {<br>	public class PersonModel : IPersonModel {<br>		public string Name { get; set; }<br>		public IWalkingStyle WalkingStyle { get; set; }<br>	}<br>}</pre><pre>namespace Persons.Database.Models {<br>	public class WalkingStyle : IWalkingStyle {<br>		public string WalkingType { get; set; }<br>		public int SpeedKMPH { get; set; }<br>	}<br>}</pre><h3>Implementation #2: Person API Project:</h3><h4>Person’s Database Project Implementation</h4><pre>namespace Persons.API.Models {<br>	public class PersonModel : IPersonModel {<br>		public string Name { get; set; }<br>		public IWalkingStyle WalkingStyle { get; set; }<br>	}<br>}</pre><pre>namespace Persons.API.Models {<br>	public class WalkingStyle : IWalkingStyle {<br>		public string WalkingType { get; set; }<br>		public int SpeedKMPH { get; set; }<br>	}<br>}</pre><p>The purpose is to serialize the interface <strong>IPersonModel</strong> that hides the implementation of <strong>Person Database</strong> project and then deserialize using the same interface <strong>IPersonModel</strong> but the implementation below will be the one from <strong>Person API project</strong>.</p><p>In order to achieve that, is necessary to create an instance of type <strong>JsonSerializerSettings</strong>,in order to indicate to serializer and deserializer what will be the concrete type it will use to perform the serialization/deserilization.</p><pre>JsonSerializerSettings settings = new JsonSerializerSettings();</pre><p>The <strong>JsonSerializerSettings </strong>instance will be instantiated with some special converters. Each converter will map one interface with one concrete type, as this information is necessary for the serializer/deserializer.</p><p>Using the concrete types from project <strong>Persons.Database.Models</strong></p><pre>class PersonModelConverter : JsonConverter<br>        {<br>            public override bool CanConvert(Type objectType)<br>            {<br>                return (objectType == typeof(IPersonModel));<br>            }</pre><pre>            public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)<br>            {<br>                return serializer.Deserialize(reader, typeof(Persons.Database.Models.PersonModel));<br>            }</pre><pre>            public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)<br>            {<br>                serializer.Serialize(writer, value, typeof(Persons.Database.Models.PersonModel));<br>            }<br>        }</pre><h4>Using the concrete types from project Persons.Database.Models</h4><pre>class WalkingStyleConverter : JsonConverter<br>        {<br>            public override bool CanConvert(Type objectType)<br>            {<br>                return (objectType == typeof(IWalkingStyle));<br>            }</pre><pre>            public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)<br>            {<br>                return serializer.Deserialize(reader, typeof(Persons.Database.Models.WalkingStyle));<br>            }</pre><pre>            public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)<br>            {<br>                serializer.Serialize(writer, value, typeof(Persons.Database.Models.WalkingStyle));<br>            }<br>        }</pre><pre>Initialize JsonSerializerSettings instance with the above converters so the serialzer will know which concrete type to use in order to serialize/deserialize the IPersonModel object.</pre><pre>JsonSerializerSettings settings = new JsonSerializerSettings()<br>        {<br>            Converters = new List&lt;JsonConverter&gt;<br>            {<br>                new PersonModelConverter(),<br>                new WalkingStyleConverter()<br>            }<br>        };</pre><p>Specify the settings during serialization/deserialization action</p><pre>JsonConvert.DeserializeObject&lt;IPersonModel&gt;(jsonString, settings);</pre><h3>Example #1:</h3><blockquote>Choose to <strong>serialize</strong>/<strong>deserialize</strong> the interface using concrete types from <strong>Persons.Database</strong></blockquote><pre>IPersonModel Person = new Persons.Database.Models.PersonModel <br>{<br>	Name = &quot;George&quot;,<br>	WalkingStyle = new Persons.Database.Models.WalkingStyle <br>	{<br>		WalkingType = &quot;Fast Walking&quot;,<br>		SpeedKMPH = 7<br>	}<br>}</pre><pre>JsonSerializerSettings settings = new JsonSerializerSettings()<br>        {<br>            Converters = new List&lt;JsonConverter&gt;<br>            {<br>                new PersonModelConverter(),<br>                new WalkingStyleConverter()<br>            }<br>        };</pre><pre>var jsonString = JsonConvert.SerializeObject(person , settings);<br>var person2 = JsonConvert.DeserializeObject&lt;IPersonModel&gt;(jsonString, settings);</pre><h3>Example #2:</h3><blockquote>Choose to serialize the Interface using a Person object from <strong>Persons.API</strong> and then deserialize the interface using concrete types from <strong>Persons.Database</strong></blockquote><pre>IPersonModel Person = new Persons.API.Models.PersonModel <br>{<br>	Name = &quot;George&quot;,<br>	WalkingStyle = new Persons.API.Models.WalkingStyle <br>	{<br>		WalkingType = &quot;Fast Walking&quot;,<br>		SpeedKMPH = 7<br>	}<br>}</pre><pre>JsonSerializerSettings settings = new JsonSerializerSettings()<br>        {<br>            Converters = new List&lt;JsonConverter&gt;<br>            {<br>                new PersonModelConverter(),<br>                new WalkingStyleConverter()<br>            }<br>        };</pre><pre>var jsonString = JsonConvert.SerializeObject(person , settings);<br>var person2 = JsonConvert.DeserializeObject&lt;IPersonModel&gt;(jsonString, settings);</pre><h3>Further steps:</h3><p>As we have seen previously, we have created one JsonConverter for each Interface-Concrete Type pair. Imagine an example that we have 10 or more Interface-Concrete Type pairs, we would need one JsonConverter class for each and this will produce a lot of boilerplate.</p><p>In order to avoid the declaration of so many JsonConverters we could use a re-usable single class that will make the job and also make our life easier and keep our code clean and tidy.</p><h4>Re-Usable JsonConverter</h4><pre>public class InterfaceToConcreteTypeJsonConverter&lt;TInterface, TConcreteType&gt; : JsonConverter <br>        where TInterface : class <br>        where TConcreteType : class, TInterface<br>    {<br>        public override bool CanConvert(Type objectType)<br>        {<br>            return (objectType == typeof(TInterface));<br>        }</pre><pre>        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)<br>        {<br>            return serializer.Deserialize(reader, typeof(TConcreteType));<br>        }</pre><pre>        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)<br>        {<br>            serializer.Serialize(writer, value, typeof(TConcreteType));<br>        }<br>    }</pre><p>Therefore, using the above single class we could specify the types for each of our Interface-Concrete Type pairs and it’s pretty simple!</p><h3>Example #3:</h3><blockquote>Choose to serialize the Interface using a Person object from <strong>Persons.API</strong> and then deserialize the interface using concrete types from <strong>Persons.Database</strong> without defining one <strong>JsonConverter</strong> class for each Interface-Concrete type pair but to just simply use the generic <strong>JsonConverter</strong> class <strong>InterfaceToConcreteTypeJsonConverter</strong></blockquote><pre>IPersonModel Person = new Persons.API.Models.PersonModel <br>{<br>	Name = &quot;George&quot;,<br>	WalkingStyle = new Persons.API.Models.WalkingStyle <br>	{<br>		WalkingType = &quot;Fast Walking&quot;,<br>		SpeedKMPH = 7<br>	}<br>}</pre><pre>JsonSerializerSettings settings = new JsonSerializerSettings()<br>        {<br>            Converters = new List&lt;JsonConverter&gt;<br>            {<br>                new InterfaceToConcreteTypeJsonConverter&lt;IPersonModel, Persons.Database.Models.PersonModel&gt;(),<br>                new InterfaceToConcreteTypeJsonConverter&lt;IWalkingType, Persons.Database.Models.WalkingStyle&gt;()<br>            }<br>        };</pre><pre>var jsonString = JsonConvert.SerializeObject(person , settings);<br>var person2 = JsonConvert.DeserializeObject&lt;IPersonModel&gt;(jsonString, settings);</pre><h3>References:</h3><ul><li><a href="https://www.newtonsoft.com/json">Newtonsoft</a></li><li><a href="https://www.pmichaels.net/tag/type-is-an-interface-or-abstract-class-and-cannot-be-instantiated/">Seriliasing Interfaces in JSON (or using a JsonConverter in JSON.NET)</a></li><li><a href="https://stackoverflow.com/questions/24644464/type-is-an-interface-or-abstract-class-and-cannot-be-instantiated">Type is an interface or abstract class and cannot be instantiated</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=930d60db638f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>