user2414557
user2414557

Reputation: 19

DSL-Json in Java project is too slow

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?

  1. Do we have another way to use dsljson?

  2. 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

Answers (1)

Rikard Pavelic
Rikard Pavelic

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:

  • reuse dslJson instance - it's costly to recreate it multiple times during testing
  • avoid using Strings - byte[] or Streams are much more GC friendly data types

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

Related Questions