Description
So my pom.xml has following dependencies:
<dependency>
<groupId>com.jsoniter</groupId>
<artifactId>jsoniter</artifactId>
<version>0.9.23</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.29.2-GA</version>
</dependency>
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;
}
}
I got the following answer:
REFLECTION_MODE
REFLECTION_MODE
Json.Student(id=1, name=Json.Name(firstName=null, surname=Blogg))
{"id":1,"name":{"firstName":"Joe","surname":"Blogg"}}
My key takeaways:
- By default REFLECTION_MODE is used
- 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?
Sources: