我正在使用Jackson和 DataBind 库来解析 json 并将其映射到 java 对象。我还在其他不需要性能的项目上使用 Gson。
2 月 17 日,LoganSquare库首次发布,承诺解析速度比 Gson 快 4-10 倍。
- LoganSquare 比 Gson/Jackson 没有什么优势?
- 优点和缺点?
- 您在生产应用程序中有基准吗?
- 对于生产应用程序来说足够稳定吗?
我知道这可能是一个主要基于意见的问题,因此尽可能技术性和具体性,并将您的答案基于真实数据。
我正在使用Jackson和 DataBind 库来解析 json 并将其映射到 java 对象。我还在其他不需要性能的项目上使用 Gson。
2 月 17 日,LoganSquare库首次发布,承诺解析速度比 Gson 快 4-10 倍。
我知道这可能是一个主要基于意见的问题,因此尽可能技术性和具体性,并将您的答案基于真实数据。
很清楚,如果您将应用程序发布到带有 ART 的设备,您将通过解析获得巨大的速度优势。
所以我将解释到目前为止我对 logansquare 的体验。
优点:
LoganSquare.parseList()
缺点:
NO REALM DB:到目前为止,我无法使用 Realm db 运行它(我还没有努力)
自定义类型适配器:到目前为止找不到类型适配器或类似的东西,但我不确定。
在这里查看他们的基准
这是我糟糕的基准测试结果(它不是一个合适的基准测试,但它确实是):Emulator nexus 5, with DalvikVM,4.2 jellybean
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.google.gson.annotations.SerializedName;
/**
* Created by Ercan on 6/26/2015.
*/
@JsonObject(serializeNullCollectionElements = true ,serializeNullObjects = true)
public class Village {
@SerializedName("IdVillage")
@JsonField(name ="IdVillage")
String tbsVillageId;
@SerializedName("TBS_VillageId")
@JsonField(name ="TBS_VillageId")
String townRefId;
@SerializedName("VillageName")
@JsonField(name ="VillageName")
String villageName;
@SerializedName("Status")
@JsonField(name ="Status")
String status;
@SerializedName("DateInserted")
@JsonField(name ="DateInserted")
String dateInserted;
@SerializedName("DateLastModified")
@JsonField(name ="DateLastModified")
String datelastModified;
public String getTbsVillageId() {
return tbsVillageId;
}
public void setTbsVillageId(String tbsVillageId) {
this.tbsVillageId = tbsVillageId;
}
public String getTownRefId() {
return townRefId;
}
public void setTownRefId(String townRefId) {
this.townRefId = townRefId;
}
public String getVillageName() {
return villageName;
}
public void setVillageName(String villageName) {
this.villageName = villageName;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getDateInserted() {
return dateInserted;
}
public void setDateInserted(String dateInserted) {
this.dateInserted = dateInserted;
}
public String getDatelastModified() {
return datelastModified;
}
public void setDatelastModified(String datelastModified) {
this.datelastModified = datelastModified;
}
}
我在装有 Android 6.0.1 的 Nexus 5 设备上运行了 LoganSquare Benchmark项目,结果如下:
此外,在使用 lib 一段时间后,以下是我的优缺点:
优点
缺点
response.body()
它是字符串 json 响应
// MovieData 它是一个模型类
MovieData movieData=LoganSquare.parse(response.body(),MovieData.class);
Log.d("onResponse: ",movieData.getTitle());
该库自 4 年多以来未更新。
到目前为止它工作得很好,但据我所知,它会在 gradle 5 之后停止工作。