up
Litepal is what, but Baidu.
Datasupport is Litepal's most basic database object, similar to JPA's repository. The
problem is: When the Datasupport subclass is serialized with Gson, datasupport its own attributes are excluded.
Underwriting
You do not want to define another Dto object, but a subclass that uses datasupport directly will be affected by this problem.
then use the Gson gsonbuilder to create a custom filtering policy, and then remove the corresponding attributes.
public class Mylitepalgson extends Mygson {public Mylitepalgson () {super (Customizegson ()); } private static string[] Litepalexcludes = {"Baseobjid", "ASSOCIATEDMODELSMAPWITHFK", "associatedmodels MAPWITHOUTFK "," associatedmodelsmapforjointable "," Listtoclearselffk "," LISTTOCLEARASSOCIATEDFK "," FieldsToSet
Todefault "}; private static Gson Customizegson () {return new Gsonbuilder (). Addserializationexclusionstrategy (New Exclusionstra Tegy () {@Override public boolean Shouldskipfield (FieldAttributes f) {for (String
Exclude:litepalexcludes) {if (Exclude.equals (F.getname ())) {return true;
return false;
@Override public boolean Shouldskipclass (class<?> clazz) {return false;
). Create (); }} public class myGson {private Gson Gson;
Public Mygson () {Gson = new Gson ();
Public Mygson (Gson gson) {This.gson = Gson; Public <T> T Fromjson (String json, Type typeoft) {try {return Gson.fromjson (JSON, TYPEO
FT);
catch (Jsonsyntaxexception e) {e.printstacktrace ();
return null; } public <T> T Fromjson (jsonelement json, class<t> classoft) {try {return GSO
N.fromjson (JSON, classoft);
catch (Jsonsyntaxexception e) {e.printstacktrace ();
return null;
} public String Tojson (Object src) {return Gson.tojson (SRC); }
}
Knot