![]() If yes, continue private val KOTLIN_METADATA = Metadata:: class.java Parameters whose type can be NULL, regardless of whether the default value is set, can be resolved if the field is missing in the returned Json, or if the field is explicitly nullįor the above requirements, the default value of the object needs to be obtained first, and then the processing steps are as follows according to whether 1 ️ parameter is NULL, 2 discount ️ parameter and 3 parameter free constructor of data:Ĭheck whether it is a Kotlin object.For parameters whose type cannot be NULL and whose default value is not set, an exception is thrown if the field is missing from the Json or if the field is explicitly null.For parameters whose type cannot be NULL and whose default value is set, if this field is missing in the Json or is explicitly null, the default value is used instead.We need to achieve the following objectives: We can write a custom TypeAdapterFactory to complete our support for Kotlin Data Class. The Gson framework can intervene in the Json data parsing process by adding a TypeAdapterFactory. ![]() JsonDataException is also thrown if a field is missing from Json and the default value is not set for that field. Moshi validates Json parameters that explicitly return NULL, and throws a JsonDataException if the parameter cannot be null. Let's look at an example where there is no default constructor value data class Bean( val id: Int. Recently I happened to have some time, and found that this kind of problem appeared in the company's project many times, so I did a research on the cause of this problem, and sort out the treatment plan. I did not study them carefully before, but only dealt with the parameters with problems in order to fix the problem. This year, nullPointerExceptions of Gson and Kotlin Data Class were found online for several times.
0 Comments
Leave a Reply. |