Server-Client Communication:.NET 8 Core Gets a Power Boost for Fast Serialization & Deserialization!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everybody welcome back to net go up Channel I  am Frederick and I'm happy to have you here today   in this video we are going to look at some  amazing enhancement made to calization and   the calization in net 8 core maybe you be asking  yourself what the heck is realization and this   realization don't worry keep calm I'm going to  explain them to you if you know it already then   I give you a thumbs up before before we jump into  this topic let me take some time and appreciate   you for taking time to watch videos that I do  post on through this Channel and once you also   watch this video you make sure you subscribe to  the channel and hit on that notification Bell so   you never miss out any of upcoming content if  you enjoy what you're going to see today and   you're okay with it please do not forget to  give this video a thumbs up when you do that   that it helps this channel grow and I believe  you want this channel to grow too stick around   to the end of this video because trust me this  is going to be something that you wouldn't want   to missx at all IA offer training session to  those who are interested in net Technologies   talking about Blazer Blazer server that's a Blazer  assembly net Mar and Mar Blazer hybrid and also   web service talking about apis so if you want  to learn more about this please have an email   at the video description going there hook me up  over there and we can communicate also after this   video if you have any thoughts please put it  at the comment section and I'll turn to you as well those of us who haven't heard of calization  and distalization let me use just a minute to   explain that now we talk about calization it is  the act of converting object into Json string that   that's all so converting objects or models into  Json string is known as calization then what is   calization it is a vice versa of calization so  now this time around we are converting um the   Json string into the object now we are limited to  or I'm talking about net so converting net object   that model from net into Json string and that is  the calization and also converting from strength   into net object it is known as the calization why  are we talking about this today you know when it   comes to data communication from a service or  an API and a client Json is what they use for   communication that is why we need to know how to  realize and also how to dis realize this maybe   you know it already but but there has been an  enhancement um to that in net8 and that is what   I'm going to take you through well maybe you be  asking yourself what the heck is also Jason all   right so if you don't know then let me tell you  so first of all Jason stand for JavaScript object   notation it is a lightweight data interchange  format it is easy used for communication between   a service and our client it is also also easy  for humans to read and write and also easy   for machines you also pass it and generate so  maybe you be asking yourself what is Json that   is JS n it stands for JavaScript object notation  JavaScript object notation it is a lightwe data   interchange format it is easy for human to read  and write and also so easy for machine to pass and   generate it is used for communication between  a client and a server so it is very important   to know Jason because when you have your API you  need to communicate your API and definitely you're   going to be using J now when you use the Jason  you have to dis realize it as a respon from the   Json and now when communicating no as a response  from the API sorry I don't want to confuse you   today and when you're also communicating to the  API you also have to serialize or con convert   your object into adjacent so that the server the  API can understand so with this there has been   an update in calization and dis realization net  for the past couple of years since from Net 5 we   have six seven now within a there's an amazing  features that have been added to it and I call   them an enhancements okay so let's first have a  look we're going to talk about four aspect here   the first one is going to be how to handle missing  properties members during dis realization we're   going to have a look on how to include nonpublic  um properties and Constructors in Json formation   and also how to use Source generation for  calization and also this realization and   the last part here we going to talk about how  to change the name during realization by using   either Dash or underscore so how do you modify  the property name using underscore or Dash okay   we're going to have a look on these four aspect  so that's going to be for the objective of this   video so stick around so we get to the end because  this is very important thank you all right so now   let's jump straight to the first one um that is  uh how to handle missing property man during this   realization when we are done with this project  or this work I'll put it at the gab so maybe you   can just go in there and now what you've done here  you can just clone it and review let's go through   this I have an web API created fresh and new as  you can see nothing has been done and if I run   this project I have the default um endpoint as a  weather forecast and that is what we're going to   be using for this past okay so don't worry we not  going to do anything new whoa so I have to build   this again and I have to install some packages in  here so it can run well let's let's do that you   know for this time around I have to make sure  my internet is active it is working not active   only it is also working so let's let's do it again  and see because you know it has to uh restore some   packages as soon as you create a default project  okay so let's see yeah everything set ready and   you can see it is running so you make sure you do  same and run your project as well and let's see so   there's nothing here as you can see so I decided  to run this application so you know what you're   going to use now we have this endpoint as weather  forecast created by the ESP team um is INB already   now if I click on this TR this out you know we  have access to the following um data here as a   Jason format so this what we're talking about is  a Jason so this used in API communication okay so   you can see when we make an API request we've seen  this as a response okay so now let's talk about   how to handle any of them now we see this Jason  has four properties date temperature C temperature   F and our summary these are the properties let's  find out and see the actual model designed for   this so go to solution Explorer and in here can  see we have this weather forecast is a model or   it's a class as we all know now this class has  these four guid these are the properties of a   class date temperature C temperature f F and our  summary so these are the properties of this model   and that is what it is using to retrieve the data  from the API okay now we going to create another   set of um another model and instead of repeating  these four uh properties we going to remove one   we're going to skip one and I maintain three  let's say in case you try to get the data from   the API and um each will be able to receive its  correspondent property but when it gets the last   one which has been removed let's going to happen  so maybe you like to use this temperature C okay   so this let's make a copy of this um I would like  to just copy this let's create one model so we go   to our solution let's create a model here and now  with this we're going to name this as response so   you can put it any name that you want even your  name will be all right okay please don't name it   your name okay so let's see this we have the same  thing we making a copy of this and we are going   to comment this so this is having this model is  having three property is it property properties   yeah that's right it is having three properties  now okay now with this you see we have it already   so we can just make a copy of this and let's set  it here because you're going to receive from an   API we are not setting anything we going to make  um a receiving from an API okay so we have three   properties active now let's save this let's go to  our API so can be found in the controllers folder   we forecast controller and I'll check it up see  this is an API that we have okay now this is the   method that is given us so let's write another  method in here and I'm going to say this is going   to be public async is it async no because yeah  I'm not calling API yet so public task ask and   I like to use this I action interface so results  and here let's say this get weather forecast two   now in here since this is going to return I in  meaning a list you want to fish out or um filter   and get one only one model out of this right so  let's see let's see um let's get as a result is   equal to now when you call this get method it's  going to call this method now when it call this   method it's going to return a list and we want to  just pick any so we can use first or default you   can use last take we can use any of them so let's  use first of default to take the very first one   now when we are done this is what we're going  to do we are going to now serialize this into   Jon format right so let's let's have a look so  that when we call this method we can retrieve the   Json now let's see how to do that so first let's  serialize it so I'm going to save serialize um   objects I'll use the obj is equal to then we can  use des serializer and that is this do serialize   you can see we have this in here right and I will  pass in this result so this result that is this one so after serializing this it's going to  have all the properties in here that is the   four properties okay so this has let me put  the four properties in here and the properties   if you want to know when you check this we  forecast model we have all the properties   in there now this Les's after weize this we  are going to disiz it so here you can say   this is serializing now let's distalize it and  display to the screen so I'll say this is dis realizing okay now when it  come to the dis realizing   section we're going to say so this is dis realize object don't mind the the  spellings okay so I have this dis realize now here this what we're going to do now  can see that we have the serialize so we're going   to serialize it but before we do that I want  to pause this okay let me just hold on that and   let's say return okay and now serialize let's  see what we have so let's run this application   and see so we're going to return this realized  object object we serializing this results here   into a string format so converting it from  an object or a model that's for the weather   forecast model and we are specializing it to  a string format let's use an async here let's   run this application and I'll see what we have  whoa we have an error here that's right I know   I know we have an error do you also know  yes because let me show you one thing we   did not specify any HTTP verb here there's no  routes is it routes yeah so let's specify this   HTTP get and this here it is get so we let's  give it a route and I'm going to say this is f now let's see okay so you see we have it over here now  click on this and let's click on try this out   execute this let's see the response yes so this is  a response you can see that it has 10 this into a   single string okay and we have the starting and  have the ending so it looks like a key value so   there is a key there is a value key value pair key  value pair so key is a date the value here is a   date value key is a temperature C this is a value  and the same thing applies to any of this here so   we be able to serialize the data into this Json  now we want to distalize it so as I speak or as   we all speak you know we have date temperature  temperature F and our summary how many there   are four isn't it good now let's see when we go  back and I'll check our response one is missing   temperature see it is missing we have date let  me just remove this at all so we have date we   have temperature F and summary temperature C it  is nowhere to be found now we want to convert the   string Jon string into an object okay so currently  you're going to have one to1 matching but when it   gets to temperature C there's no um entity for  that so let's say one to one matching date for   date or should I even sh put it like this okay  so when we click on response and bring this out   date for date temperature C for no temperature  f for temperature F summary for summary so this   is going to be what hidden out it is out but it  is not actually out from the application it is   still there but here there's no data to receive  there's no receiver to handle that and will that   through an exception or error let's try that and  see and after that you look at the enhancement   made with it okay so anytime that you want to do  the same you want to call an API whereby you want   to um just get only a specific property from  the API response you can do that too so go to   the controller and that is it now let's visualize  this so as you have here we're going to say disiz   object is equal to now going to still use the Json  converter is a converter realizer so Jon realizer   dot we have the dis realized and now since we  going to use this object you're not going to   use WEA forecast because wether forecast has the  four properties you want to use the response that   we created which omit one property so response so  control period we can use this is there a response   I like to use response model because this response  could be an an an HTTP response okay so let's use   this model before we get ourself one so we copy  this now let make a change to this very quick and fast so response let's change it I believe  you are done can we move on okay now we have   this response so let's me response model  and now in here we pass in the string as   you can see it needs adjacent string  so let's pass let's copy this one and   I'll pass in here let's close it and now  iner of returning this let's return this   so maybe we can use console so console do  right line and now let's pass in the seriz   object so we see this the seriz object on  the screen as well now let's run this and see so the app is ready now let's click on  this our API a customized one and if I click   on execute let's see okay so we see that here we  have our date our temperature and we have this SU so we can see that um here although we've missed  one out but we able to retrieve the first three   of them that's this is the the one that we have  the temperature see it is out but of in case you   don't want to do that you want to restra in such  a way that in case you couldn't retrieve any of   the properties issu through an error how you going  to do it it's very simple that's a new enhancement   made to this realization in net and let's have a  look with that so on top here where we have this   model you see we have three properties here now on  top here we need to specify an attribute and now   this attribute is going to be Jason unhandled map  member handling Json unmapped member handling and   I in here specify this as unmap member handling  the same thing so un map member handling now   it has two modes or it is it has it is in two  modes okay so the first one oh we didn't do it   well let's see it again so that's ad Jon okay so  it is in two modes and now the first one we have   disallowed and allowed or skipped so default  I think Skip is for the default that is why   in case you even miss any of them we still able  to retrieve the the last one or the rest let's   set to disallowed and I'll see now disallow so in  case it couldn't retrieve any of the properties or   there's an overdose of property from the service  or from the server to our response then it's going   to dra an error let's say this and now let's say  so let's click on it again and I'll try this out   execute this and I can see we have an error Here  and Now what does it saying temperature C could   not be mapped to any net member contained in  the response model so it means we have this   temperature C model missing okay so quickly go in  there and I'll add it this is just an enhancement   made to this so if you want to also allow it  maybe in case you have a huge list of Jon that   you want to allow maybe you can just go in for  Skip and now skip since it is a default one it   is also going to just skip it and that be won't  be any issue so let's see try this out execute   and we see we still have it so that is the first  enhancement made to that now let's go to the next point so the next one that we're going to have  a look here it is how to change property names   during um Jason formation you know properties  have default names as soon as you create them   you give them the names now when we check our  project we see we have this the default property   we have it over here already now let me since  you're done with this you can just skip this   and I return okay so this just a respond you're  not going to use this response we're going to   use this weather forecast uh model in here so  when you switch to this weather forecast you   will see these properties they have their names  differently we have day temperature C temperature   F and summary now the in defaultly when a Json is  being sent from a server or an API it uses a camel   case maybe you be asking yourself is it the first  time of you hearing this camel case whoa what is   actually C case it is something not difficult  it's very easy and it is a case whereby or it   is states that when creating a variable in your  application always start with lower case do you   not start upper case example here is when you go  to this WEA forecast you can see say that I made   a serialized object now s here is a lower case  and now the object is what the upper case why is   this useful there are lot of Reserve keywords  in application that we do that is a framework   here that we see if I want to write something  a variable to handle maybe Jon realizer as soon   as I start with lower case it is fine but what  of in case start with uppercase then it's going   to be like you're calling that keyword that is  the reason why always start with lowercase that   is what we use in camel case but this some round  there are also another two cases that have added   to the camel case so what are these the first  one is called snack case or is it snake case   let's see snack or snake case it depends on how  you going to pronounce it by I say snack maybe   going to say snake okay and that is ass with  underscore and we have the Kebab case Kebab   that's fine Kebab case and that's for hyphen so  you can rename your properties using underscore   and now hyen let's quickly have a look so in that  we need to specify something in here and that's   what we known as Jason options so options are  the additional data that you want to add when   converting from the model to your not your object  to your Json string now let's see so we have this   we want to create an object or option here  so we're going to say V option is equal to   jent realizer option and that is this one so  in this you can specify something like here   okay the first one is see we have the property  property name so take note we have property name we forgot you add new is very important  we creating an instance of it not the actual   um one key so property name we can have it as  can see property name we have case insensitive   can set that to true and check this we have  naming policy now of this naming policy let's   have a look defaultly that is the camel case that  I spoke about but this time around you don't want   to use this camel case in our response we want  to let's check that response you can see this is   a response temperature f t here is a lower case f  is the upper case that is a c case you want to use   maybe Kebab or snake or snack in such case with a  snack you're going to have underscore going to be   temperature and _ f for the Kebab it's going to  be temperature hyphen f let's try each one and   see what I'm talking about so inste of the camel  case we're going to use you see we have the snake   or the snack case lower you can also use snack  case upper let's close this now when youzee this   we can specify this to the options here because  the options must be the same so let's pass in this   option and going to use that for the calization  and now when we are done and we want to deize it   use the same thing so one bed is killing one stone  is killing two beds isn't it okay so we have this   let's save it and now let's see let's set this  out okay maybe we can bring our this time too   so you can see that's the first one I did not  even show you this that is a date temperature   temperature F and the summary all right now if  I click on our end point this time we going to   use the camel not the cam case s case so try this  out okay so it seems like this did not work let's   check this also all right so this worked we  see from here temperature and _ C temperature   underscore F right and take note you can see that  all of them they are in lower cases C is in lower   case f in lower case isn't it now let's put it  here because this will make it clear now when   you go to the same section dis realize we want to  so let's copy this and that is this one okay so we   are dis realizing it by this time around inste  of using this response model we are going to   use this weather forecast so let's change this to  weather forecast let's save this now let's test it out okay so this is not still working let's see oh now I get it I know you've you've  gotten that already now when we are dis   realizing it it won't show us that camera  case issue we're going to see the at turn   because you are converting it to this  weather forecast prop or model and the   properties in there Al going to be displayed on  the screen but here since going to be a string   you're going to see the formatting okay  so let's pass in this and let's display that and now here we're going to see what we saw  so check that out you can see we have temperature   underscore see now all these are in lower case so  if you want to handle your properties in the Jon   format in this way don't forget it is very simple  use the snack case now you can also change this to   Upper this case lower so check so snack we see  we have upper save that and now let's check it out so try this out execute and now see  you can see it is in upper case all right   so that is also one thing that you can do  now let's have a look with the other one   with the dash this is just underscore and  that's a snack let's see with the Kebab   or how how you going to pronounce it kab or  Kebab Kebab lower K say that and let's see so try this out execute and now check it out you  can see that we have the hyphenated and now when   you change this to the uppercase to you're going  to have it in an uppercase form there is a new   enhancement I think so because according to the  docs it said it is it can be applied to net 8 all   right let's go to the next one which is including  on public properties and Constructors in Jon formation so maybe in your model formation you  would like to make some properties as internal   or private you wouldn't want to call them or use  them anytime that you call the model you like to   have an inbuilt uh method to set values to these  properties in such case it's going to make it the   the is it the signature type going to be maybe  internal or private but in case you want to use   it in the J formation do you have to go back and  um change from internal to public because you know   J information has to deal with the properties  which have public as their signature let me   show you this you can see when we go to this  weather forecast we have our signature here   you can see this a public and we have a data type  as integer and I a temperature F now this here it   is exposing this property outside when you call  this method when you call this model sorry that   is it model okay you can have access to this  temperature F because of this guy here public   so hello I'm public anybody can have access to me  that is what they is saying now I don't want to   do this this field has to be set set internal so  in such case and I want this in a Json formation   is it possible to get that property out yes  the new enhancement here made it let me show   you or let's all learn together let's add one  property so first of all this is going to be internal so this internal okay now with this  internal let's see if I save this reu   this application now that is a date time  or date only let's check and see when you   make a query from an A Endo let's see  if you're going to have access to this date let's click on our end point try this out  now execute it and let's see you can see the   internal property is off it is out because it is  not public so we can't have access to it so when   you have this in your model and maybe you're  using for a particular purpose and later on   if you want to get a Json out of it meaning you  w't get it unless you go back and change it to   public so let's see the enhancement made to this  so we can have access to this method now we go   back to the same section now on top here on top  we're going to specify this attribute on top and   that is known as Json include so Json include  this put it on top leave is internal as it is   put this on top anytime it's a Jon formation  it's going to check all those properties that   have this Json include as an attribute on top  and it's going to grab them by hook or cook if   you have internal um uh that is a signature or  whatever thing that you have as soon as I have   this property on top of you then I'm going to  use you in the formation okay now if I save   this and now let's have a look again the second  time the same end point now let's see if you're   going to have access to the that field yeah  then we have it because we have the date so   that is the one way another one here is maybe  you're going to have another property that you   wouldn't want to set value to it by it's going  to depend the value in here let's see so this   is going to be um temperature C temperature  F right we want to say that um public then   total I don't know what your total but here  let's have a total maybe this is going to be in okay now in here we are saying that it is  returning this temperature F temperature C   let's by what was it by addition let's let's  add it temperature F so you see that this we   are not going to it doesn't have the get or set  assessor so it means we are not going to assign   any value to it this is going to depend on the  values obtained for this temperature C and our   temperature F we're going to add the and I assign  it to this total when you do this this will work   but let's see the next one where you want to  use Constructor as soon as the page is called   the model is called you want the Constructor to  initialize this okay so here let's have our get   and now set assessor you can make this as internal  and now you can make this as internal as you done   internal already you know what internal going  to do and as soon as you passing internal it   mean you must pass in Json include isn't it Json  include okay now you can also make this as public   just we just trying it to see and now here let's  create a Constructor here so we can just pass c   o r that's a Constructor and now when the page  loads this internal that we have we going to say total is equal to the value of this so we can now paste this okay so saying total is equal to this  plus this as soon as this get their data   then it's going to assign it to this total  um property here and now when we have this   we this is going to be exposed to the public  soon as it is public it means it's going to   be exposed but know this is something that it  is internal we don't want anybody to override   this assign any temperature to this we want to  assign them here and as soon as the value of   this changes then it has to also change here  in in doing so we have to set here as also internal okay so internal means no  one can have access to this method   now let's save this let's re this  application and I'll try this out so the app is ready now let's click on our end  point and I'll see what we have now so if I click   on this and I click on execute this let's see  the response okay so we have 500 status error   code and what is it saying it is saying that a  visualization of a type without a parameterized   Constructor singular parameter Constructor and  etc etc okay what you can actually grab from   here it is we have to Constructor annotation with  Json Constructor attribute it is not supported   okay so for now based on what we've done this  is not supported let's make it support we can   do that from the same section now on top here  maybe you'll be asking yourself or be giving um   a su here that why don't we include the same  Jon include on top of this no take note this   is not a property it is a method it is just  a Constructor method that is over here so we   cannot specify this attribute on top but it  has its own attribute that is known as Json   Constructor okay so put that on top and it's  going to make this public so Jason Constructor   that is this one put it on top like that save this  let's do it again and see what we're going to have yes so now we have it we have one left let's  talk about that one too and that is how to use   or using Source generation for civilization and  now theorization according to Microsoft documents   on um system. test. Json you know that is the name  space where we have all these guys from you know   we have system. test. Json realization right so  that's what we have everything these guys and   all the Jason sections or these Jason boys from  According to the documentation on this by default   this system. test. Json gathers the metadata it  needs or all the necessary data that it needs to   access properties of object for calization and  onization at a run time using reflection so when   the app start this system test. Json has to gather  some metadata some data that you need around your   object that you're going to create when using in  communication from API sending a request and also   receiving a request and now dualizing it oring the  the um the object and I return to the AP again it   is a work of this system. test.js to gather this  metadata around so you can use in theorization and   now detalization but times when dealing with this  it it can slow the process the reason is when you   are dealing with large object maybe a model which  has a l large properties it's going to take time   to do it so to increase the performance so this  technique has been in existence since net 6 I   think so net six and the not Net 7 and yeah net 6  later version of net 6 and now the the C language   version must C 9.0 or later so that is where  this um enhancements were introduced but maybe   let's go through and let's see if you've used  this before if you've used it before okay there   are four ways that we can use it for method and  they are one you can use the Json type info and   now this needs a t value we can also use jizer  contest all of the I'm talking about you want to   use use the instance and now the the next one is  you can use jonyer options and I believe we even   done one here and I think these are the three  ones yeah three so let's have a look with each   how to use any of them to encrypt is it encrypt  who serialize or dis realize your object so we   go back to this weather forast and now in here  the same method this is for the realization and   I this visualizing let me just copy this and  let comment it okay now the very first thing   to do here is you go to this the class the class  that you going to be using for this communication   for visualization and our distalization let's  say this is a class okay or we have this class   let's create another one because here we've we've  tempered this so let's make a copy of this and   I use it so let me copy this and I'm going to  say this is going to be whether forast one so   or let's put into the this response no let's  create one so add a class and I say weather forecast we forecast one let's past in this so  we have these four properties and this must be   public as usual okay now that we have this we go  back to the controller weather forast controller   and in here we are going to serialize it with the  three method that I spoke about okay so first here   let's have a look with the first one so let's use  this and that's the first method using this Json   type info so the class that you're going to be  using you have to create an partial class to this   okay so it's a partial class now with the same  method is the same model that we are going to use   let's count down here and I we have to specify  gr as an internal you know this is a limited   is an internal work and I set to partial and I a  class now in here let's set our source generation contest so contest now this I believe you can make  change to this and it has inherit from this   Json realization or realizer contest so Json  realizer contest so that is a key thing here   it has inherit from this okay and after the  inheritance that's all nothing is in again   but you must specify the type the type of this  at the we for cast on top so I have to put it   like this and on top here specify the Json  Source generation options so write indent   and set to through and now Jon realizable type  of set this to weather forecast because that's   the weather forecast that you're going to be  using so if it is another class that you're   going to be using you definitely have to change  the class here okay also you can also set a type   of again let's let's make a copy of this you  can set this to let's say boo you can set it to string so you can set this to um string integer  any data type when any of these members here   has an object you can see object means the data  type it is not well cleared it's not identified   so object is like a container a general container  that can handle all sort of data type so if it is   object then you need to specify the type of the  data that the object going to handle you need to   add it here but in case you do not have any of  this as for this example this is the day time   this is integer and this is string so this I have  then specified clearly then I do not need to use   any of this so you have to use any of these have  to use this when you have object as a type take   note okay now this is all thing that we need to  do we're not going to pass in anything here where   you need here is aable with a type of the model  that we going to use and here it is a weather   forecast one thank you forting me and we have  this now let's go to the controller and now in   here we're going to use this Json type info how  are you going to configure this do you have any   idea let's have a look so let's have our string  Json object the same thing Json object is equal   to we're going to use this um Jon realizer and  going to serialize this so serialize this and   now in here take note we are going going to pass  in oh so we need to copy this okay so let's copy   this and now past it here because you are getting  a copy of this so we just retrieving one from the   list that we have from this mod or this method  now in here let's pass in this results so I like   to use um let's say this a result okay so let's  copy this and I'll pass in here now when we are   done you know when specifying Jason options  you have to put it next to the model okay so   in here what you do here is specify the source  now you can have Source generation contest you   know where you are getting it from we getting from  this weather forecast where where is it whether   forecast one this Source generation contest  which inherit from this J realizer contest   okay so in there we are passing it in there  and now it have has a default to the weather   forecast take note weather forecast so this is  an option that we are passing in and here it   is known as the using the Json type info because  of the type of check this because of the type of   that we specified on top here we can be able to  retrieve it from uh list from this default okay   now we have this um encrypted encrypted realized  let's return okay with this so let me grab this   the next line let's return this Json obj so  that is it now let's save this let R this and see so if I click on this and I click on try this  out so execute and now we have this it is saying   unable to cast object of the type WEA forecast  two whether forecast one yes we've mismatched   it so now let's see we are using this weather  forecast one but weing data from this weather   forecast take note so let's make it as one  one okay so our set let's do it again so and apply okay so we see that we have the Json and  that is it so see we have these keys and we have   their values respectively okay so that's the first  one using this Json type info which carries with   a t value and in this case going to be the model  that we specify as a weather forecast one model   let's have a look with the next one and that is by  using Json realizer context so using Json realizer   context let me let's go to the application and  now here I'm going to to say using this jonyer   contest so with this what we're going to do here  is we can just make a copy of this and I'll paste   it down here remember that we have it set as  the S generation class in here and that's what   you're going to be using all the time so Source  generation contest now when you go back to this   um weather forecast controller down here we have  let's comment this since we are done using it and   now we get the same result from the this method  and now here you can see that we are spying Source   generation contest. default. the model so this  time around you're going to do that you're going   to make it Source generation contest. default  and now we have to specify the type of here so   type of and at the type of here it is a weather  forecast so one so it is actually works the same   it depends on you which one that you want to  use so here specify the type of within the line   but the other one the first one here is have to  use the default and I use this model at the end   okay save this and let's try this out also and  let's see what we're going to have now so it's   going to be the same try this out and I we see  we have the same thing let's see the next one   and that is a using calization options so using  thisiz that is Aizer options isn't it okay so   with this we have to um explicitly specify the  S generation context here so we're going to say that so we can say V Source generation option  is equal to new Jon cizer options okay and   now in here we are we are going to specify  the type of so here we need the type info   resolver now the type of here we're going  to specify it to the S generation options   dot okay so it is not this one we need the  one from the class so this what I'm talking   about this one we can just make a copy  of this then we say dot then we see we   have this default and we have to close  it now let's return this or let's copy this and I return okay but before that we are  going to now serialize the data first so in   here we're going to say realize but let me just  put this to sleep okay so with this St let's copy one all right now once you have this s Generation  Um options you can just make a copy of this and   I will go to jonyer doize and this time around  you're going to use this result as you know then   type off weather forecast and now instead  of this we specify this explicitly here so   we can remove everything from this section and  now past what we just specified this one so it   is the same thing just that it has work around  that you can use let's save this and now let's see and you see here too we have  the same thing isn't it yes we have   so these are the three method that you  can use to realize it now when it comes   to this realization it works the same  let's quickly have a look with each of them so let's go back here and let's  use so I'm going to also commment this   control since okay we have one here  isn't it now um let's use that so here okay let's go in for the dis realization okay now the first method that we're going to  create here we're going to say whether forecast   or whether forast data so let's create as a  variable then we're going to say it's equal   to Json realizer you must have the call sign  here we a Jon realizer do thisiz then here we   need to specify some aspect in here and what is  the first one that a model so this is a weather   forecast one remember that weather forecast  one also open this and now let's specify the   string so this is our string this is the um  Jon object copy this now paste it in here   well let's go back and see so copy this one and  in here we have to paste this okay aside from   that you need to specify the options so with  the options we can use Source generation the   same Source generation so dot then we can go  in for the default so default as you can see   then weather forecast and know if I do this I'm  talking about which one let me put this to the   next line this using the type info so this one  type info that's you need to specify the default   corresponding to the model so where is it I can  copy this on top here so using type info for the   visualizing the object okay so this and I return  this weather forecast so this going toize it now   if I click on this let's save this and now  let's find this application and see what we have so I click on this try this out execute and  if I here see we have this a model and we have all   the data being retrieved in here if I check this  Jon see we have it in the Json format and I have   initialized in here so that is the the Json type  info okay you have the same thing now let's go   to the next one and using the cizer context we can  do the same thing with it so I'll just put it here   and I will say using this so I'll just grab the  same thing and I'll put it here let's comment this one so with this what you're going to do  here is after you passing object here and   we can inste of this we can use a type off so  type off then pass in your weather forecast   whether forecast one and here we don't need to  specify this whether forecast again because it   has specified has a type so let's put comma  and I remove this witha forecast one default   okay so once you have this we need to then so as  we need to then cast this so as weather forecast   one okay so we have to remove this now we have  the this is the string so the type off is over   here already so you need not to specify the  type in here again you know we do this to   specify the T value that is the type and now  since we are specifying the type of within the   parameter here we don't need to um bring that  so that's why we remove it and I we cast it   to this weather forecast one that's the model  that we use so when you save this put a break point and I return this with forecast  so if fact click on try this out and I   execute it if I the mouse you can see  we have this the object that we have   temperature here it is zero is that so  temperature here is zero yeah that is it okay now let's have a look with the last  one so execute this and we also have same   let's see the last one and that is using  the JavaScript oh Jason realizer options   that's the last one let's see that so in  here the same section I'll just have to   comment this and I'll give it to this and  here let me just copy this and I'll paste it okay and now let's un comment this so it is  simple what I can do here is you see we have have   the same thing set up here that's the first one  the last one so we can just make a copy of this   and now ins of the cizer we're going to change  it to this realizer and we move on this is very   simple so let me just grab this and command them  and we are creating a s Generation section so here   let me this is we have one created already right  so this is the one that we've created and we can   use it into this method as well so there's no need  to create it again we can remove this now once   we have this Jon obj that's the object um Jason  serializer serialize so not serialize rather the serialize so the seriz and now with this two we do  not need to specify the object here we are going   to pass in the result so this is the result in  here so let's specify in this and also we have to   specify the type of so that is a type of and the  last one is the inste of we have to speci the same   Source generation options and that is this one so  Source generation options so we have same in here   and you know s is going to return as an object we  don't it is no more string so rather going to be   an object okay then this let's say this is the  result then we can return this result let's see   is ited already okay so it's used already results  one then results one let's put a breakpoint here   save it and let's refresh this application click  on this try this out execute it has been hit if I   click on this I have the model in here all right  so that is it now in this video we've seen the   four aspect that we decide to talk about that  is handling missing properties members during   dis realization also how to include nonpublic  uh properties and constructed in Json formation   using Source generation for both realization and  our dis realization and now changing the name by   using the dash and the dash is what you know as  a kebab case and now the underscore is the snack   case thank you so much for watching this video  I am actually grateful for that I'll put this   at the G tab so check the description too that  is the reason why I commented them so you can   actually go through with them as well um take care  and I'm going to catch you up in the next video
Info
Channel: Netcode-Hub
Views: 750
Rating: undefined out of 5
Keywords: JSONEnhancement, ServerClientCommunication, Serialization, Deserialization, .NETDevelopment, CSharpProgramming, PerformanceBoost, TechUpgrade, .NET 8 Core, JSON, ServerClient, .NET, CSharp, Performance, TechUpgrade Search Keywords: System.Text.Json update, Fast serialization, Efficient deserialization, Server-client communication, .NET enhancement, C# programming, JSON performance, Coding optimization, SON, Server, Client, Speed, C# Upgrade, Tech
Id: od-eKFiPmjM
Channel Id: undefined
Length: 61min 11sec (3671 seconds)
Published: Mon Nov 27 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.