在Java项目中实现dsljson时,我发现这是不正确的。这是非常缓慢和难以实施的。Java项目中的DSL-Json太慢了
创建从JsonObject
public static class abc implements JsonObject {
public final int x;
public final String s;
public abc(int x, String s) {
this.x = x;
this.s = s;
}
public void serialize(JsonWriter writer, boolean minimal) {
//parse the instance of object (abc) to json-string
}
public static final JsonReader.ReadJsonObject<abc> JSON_READER =
new JsonReader.ReadJsonObject<abc>() {
public abc deserialize(JsonReader reader) throws IOException {
// Use jsonreader and common json converter (numberconverter,
// stringconverter) to parse json-string to an
// instance of object (abc)
}
};
}
实现了我创造新的新的对象:DslJson<Object> dslJson = new DslJson<Object>();
打电话时使用“反序列化” /“连载”。
我想,我的实现是不正确的,因此它太慢了。 因此,如果您有任何关于此lib
的经验或示例,那么您能帮我提供一些关于这方面的想法吗?
我们有另一种方式使用
dsljson
吗?DslJson
不能使用像JackSon
?ObjectMapper mapper = new ObjectMapper(); String jsonInString = "{\"age\":33,\"messages\":[\"msg 1\",\"msg 2\"], \"name\":\"mkyong\"}"; User user1 = mapper.readValue(jsonInString, User.class);
“dsljson是最好的LIB解析“,说谁? (也许除了作者),你是如何衡量它太慢?看看这个:https://stackoverflow.com/questions/16230726/what-is-the-fastest-way-to-deserialize-json-in-java和/或Google的“快速json解析器”。 –
这是Java JSON库的序列化和反序列化的性能测试(https://github.com/fabienrenaud/java-json-benchmark)。在我的项目中,我使用了大约30000条记录来检查性能。 – user2414557
我建议你自己尝试一些库,而不是选别人说的最快的库。他们可能犯了一个错误,你可能会做一些错误,这在使用另一个lib时也会出现。您可能会错误地衡量解析,别人无法分辨。 –