I am making a Travel app project consisting of a backend coded in PHP and a UWP app (frontend) coded in C#.
Following represent the "Holiday Package" class implemented in C#
public class Packages
{
public string PackageID { get; set; }
public string Name { get; set; }
public string Destination { get; set; }
public string Description { get; set; }
public int Duration { get; set; }
public float BasePrice { get; set; }
public List<string> Images { get; set; }
public HotelInPackage Hotel { get; set; }
public string TransportType { get; set; }
public Packages(string packageID,string name,string destination,string description,int duration,float basePrice,List<string> images)
{
PackageID = packageID;
Name = name;
Destination = destination;
Description = description;
Duration = duration;
BasePrice = basePrice;
Images = images;
}
public void HotelConstruct(string hotelID,string name,int cat)
{
Hotel = new HotelInPackage(hotelID, name, cat);
}
public void SetTransport(string transportType)
{
TransportType = transportType;
}
public void ChangeImageName()
{
int i = 0;
while(i<Images.Count)
{
Images[i] = string.Format("Assets/CitiesPlaceholder/{0}.jpg",Images[i]);
i++;
}
}
}
Following is the JSON string returned by the backend
{
"PackageID":"P280",
"Name":"Sigapore Dreams",
"Destination":"Singapore",
"Description":"lorem ipsum,dolor sit amet",
"Duration":5,
"BasePrice":999.2
}
I want to deserialize the above JSON string into the "Packages" class thereby setting its "PackageID", "Name", "Destination", "Description", "Duration" and "BasePrice" properties i.e. I want to set only a subset of properties using web data
How to implement the above solution using the DataContractJsonSerializer class?
Do I need to Add/Modify any Constructor?