Reputation: 19
When implementing dsljson in Java project, I see this is not correct. It is quite slow and hard to implement.
I create new object which implements from 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)
}
};
}
I create new : DslJson<Object> dslJson = new DslJson<Object>();
to call "deserialize"/"serialize" when use it.
I think, my implementation is not correct hence it is too slow.
So if you have any experiences or example on for this lib
then can you help me provide your ideas about that?
Do we have another way to use dsljson
?
DslJson
cannot use like JackSon
?
ObjectMapper mapper = new ObjectMapper();
String jsonInString = "{\"age\":33,\"messages\":[\"msg 1\",\"msg 2\"],
\"name\":\"mkyong\"}";
User user1 = mapper.readValue(jsonInString, User.class);
Upvotes: 1
Views: 8519
Reputation: 496
There are few examples in the library repository, eg: https://github.com/ngs-doo/dsl-json/blob/master/examples/Maven/src/main/java/com/dslplatform/maven/Example.java#L82
Some things to try:
If DslJson is not the fastest, most likely there is something wrong with your setup :) (which means you should show more code - how exactly are you testing/benching library)
Upvotes: 2