Following is a class I wrote to do a simple test with javaassist enabled
public class Json {
public static void main(String[] args) {
System.out.println(JsoniterSpi.getDefaultConfig().decodingMode()); // REFLECTION_MODE
System.out.println(JsoniterSpi.getDefaultConfig().encodingMode()); // REFLECTION_MODE
JsonIterator.setMode(DecodingMode.DYNAMIC_MODE_AND_MATCH_FIELD_WITH_HASH);
JsonStream.setMode(EncodingMode.DYNAMIC_MODE);
String json = "{\"id\":1,\"name\":{\"firstName\":\"Joe\",\"surname\":\"Blogg\"}}";
Student student = JsonIterator.deserialize(json, Student.class); // decoding to Student.class
Any any = JsonIterator.deserialize(json); // decoding to any
System.out.println(student);
System.out.println(any);
}
@ToString
public static class Name {
private String firstName;
public String surname;
}
@ToString
public static class Student {
public int id;
public Name name;
}
}
When javaassist is added, I have to enable flags to open java modules. For example, --add-opens java.base/java.lang=ALL-UNNAMED
The attributes of a class should be public if we serialize/deserialize using javaassist
Question 1:
I need to verify above points and whether or not I understand them correctly. I need the absolute fastest possible encoding/decoding speeds. Is the way I utilized above libraries correct?
Question 2:
Suppose I just want to use simple lazy parsing with Any like this: Any any = JsonIterator.deserialize(json);, does javaassist still make a difference in speed here? Provided I do not map to any of my clsses. Just keep deserializing to Any object and use it like a Hashmap. In simple terms I only want to use Any and Iterator APIs. Do I still need javaassist to get the performance boost?
So my pom.xml has following dependencies:
Following is a class I wrote to do a simple test with javaassist enabled
I got the following answer:
My key takeaways:
--add-opens java.base/java.lang=ALL-UNNAMED
Question 1: I need to verify above points and whether or not I understand them correctly. I need the absolute fastest possible encoding/decoding speeds. Is the way I utilized above libraries correct?
Question 2: Suppose I just want to use simple lazy parsing with Any like this:
Any any = JsonIterator.deserialize(json);
, does javaassist still make a difference in speed here? Provided I do not map to any of my clsses. Just keep deserializing to Any object and use it like a Hashmap. In simple terms I only want to use Any and Iterator APIs. Do I still need javaassist to get the performance boost?Sources: