The following are some of the minor issues that I encountered at work today:
1. because the business needs to call the PHP interface, the returned body needs to be processed logically. However, the parameter received by a field is Io. serializable type. The field type is not the expected string type. At that time, it was a little awesome because it was a pattern match using Scala's match case. I didn't think much about it. Thanks to my colleague, I remember that string actually implements the serializable interface, even though I/O is returned. serializable type, but can also be received using string;
2. call the PHP interface and accept the response body using jsonobject. However, some fields are null. The instinct is to convert gson to an object and use Scala's option to receive fields that may be null, however, when the program runs, an error with no ARGs will be reported;
Solution: Use Case class to receive responses from the PHP interface. You do not need to add option to a field that may be null. Instead, add isjsonnull to the field in jsonobject, when the following build thrift returns the body, these fields are defined as the build of the Option type;
In fact, it is okay to use case class to determine and obtain fields. We will conduct an experiment tomorrow;
Val uesrname: Option [String] = response. get ("data "). getasjsonobject. get ("username "). isjsonnull match {case true => none case false => some (response. get ("data "). getasjsonobject. get ("username "). getasstring )}
Common Scala pattern matching