problem description
restful development mode, however, when the front end gets the data sent from the server, many of them do not give default values, and many of them are caused by null, such as the string .toString (), length, and so on.
if each field determines whether it is null, before each use, it feels inefficient and easy to forget, is there a good way to deal with it uniformly.
in the past, when working as a server, you can configure some parameters before serialization and set the default values when there is no data, but the server sometimes forgets to configure, or they are unwilling to do this step. and it is really unreliable to rely entirely on the server to do these things. The front end should have its own better fault-tolerant mechanism.
the environmental background of the problems and what methods you have tried
originally wanted to write a common method to determine the return data type when the request is returned. If it is an object, it traverses each property, determines the value, and sets the default property. If it is not an object, do other settings.
but in this way, every returned data will be processed in this way, which does not feel very efficient.
what result do you expect? What is the error message actually seen?
expect an elegant and efficient solution. If it is the same as what I said above, please wait with me for a better way.