Posts

Showing posts from May, 2020

An extra .0 when returning JSON response that contains decimal type

Sometimes when we are designing API responses, we might want to return a JSON string which contains decimal-type field. We could easily represent the decimal-type field with string, so the response is in the following format: {     "amount": "3.00" } However, for whatever reason, if you want to return the amount field   in decimal, and let's say it is very important the number of decimal place is shown correctly, there is some configuration required to get that right, as without any intervention, the client will end up seeing something as follow. *I am writing this based on the API designed using .NET's tech. stack. {     "amount": 3.0 } Assuming we want the amount to be returned in 2 decimal places, 3.00, we could achieve that with the use of attribute. Let's start by creating a class with a property called amount . public class Receipt {     public decimal amount { get; set; } } At some point, we want to serialize the above

Add current Git commit to web.config on each build [.NET Core/ASP.NET Core]

*Docker service might eliminate the following technique's usability. In this post, I am going to demonstrate a way to actually write the current commit of your version control module (I am using Git) into a location, let's say in your web.config . One of the issue I have faced when managing multiple console apps., or even web projects is that it is not easy to keep track of the com mit which the applications belong to. However, there is a simple technique to actually write the current commit of a specific branch into a location inside your project. The technique is the same regardless of the project type. * I am talking about .NET based projects. Although I only tested this in .NET Core based projects, I am pretty sure it works almost the same in .NET Framework/ASP.NET MVC based projects. The main idea is the utilize the build engine, MSBuild, to do something after building your application. The command execute a task could be derived in your .csproj file. You can defin