download:Android application building practice + principle in detail
Based on the latest construction tool chain, this course takes the development and release of a page routing framework as the main line, combines actual practice with theory, and deeply learns Gradle’s popular compile-time annotation processing, bytecode peg and other advanced technologies, leading everyone to systematically master the knowledge of Android application construction and improve the development efficiency. Technical language: Groovy/Java/Kotlin Android: Mac IDE: Android Studio 4.0+Gradle: 6.0+ Android Gradle Plugin: 4.1.0+ public Class ObjectIdConverter: JsonConverter { public override bool CanConvert(Type objectType) { return objectType == typeof(ObjectId); } public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType ! = JsonToken.String) { throw new Exception( String.Format(“Unexpected token parsing ObjectId. Expected String, got {0}.”, reader.TokenType)); } var value = (string)reader.Value; return String.IsNullOrEmpty(value) ? ObjectId.Empty : new ObjectId(value); } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { if (value is ObjectId) { var objectId = (ObjectId)value; writer.WriteValue(objectId ! = ObjectId.Empty ? objectId.ToString() : String.Empty); } else { throw new Exception(“Expected ObjectId value.”); Add a line of code to the ObjectId field
[JsonConverter(typeof(ObjectIdConverter))] public string _id { get; set; } If Newtonsoft’s JsonConvert is used, additional parameters are required
JsonConvert.DeserializeObject(json,new ObjectIdConverter());
3, after Ignore, a very skillful writing method
[JsonIgnore] public override ObjectId _Id { get; set; } [BsonIgnore] public string _IdStr { get { return Id.ToString(); } set { ObjectId id; ObjectId.TryParse(value, out id); Id = id; }}