I am using vertx i need to transfer data using eventbus from one verticle to another so in order to fast that process need to serialize and deserialize data to save memory as vertx keeps messages in queue and also performance and time as converting JsonObject to String is slower than converting using gson. Below is my sample code:
package com.test;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.ToNumberPolicy;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
public class Test44
{
private static Gson gson = new GsonBuilder()
.setNumberToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE)
.setObjectToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE)
.create();
public static void main(String[] args) throws Exception {
var js = new JsonObject();
js.put("test","dddd").put("aaa","dddd").put("res",new JsonObject().put("interface",new JsonArray().add("aaaa")));
var s = gson.toJson(js);
var d = gson.fromJson(s,JsonObject.class);
System.out.println(d);
}
}
In this i get following output from above code
{"test":"dddd","aaa":"dddd","res":{"map":{"interface":{"list":["aaaa"]}}}} but i need following when i decode json back from gson string
{"test":"dddd","aaa":"dddd","res":{"interface":{["aaaa"]}}
Any idea how it can be done
i am using following lib vertx-core 4.4.0 and gson 2.10.1