Support Java 14 Records
Would it be possible to support java 14 record classes without needing to manually create type adapters?
Currently (as of Jankson 1.2.0), when trying to deserialize a record class via Jankson#fromJson(String, Class), it simply returns null.
Serialization however works just fine.
Small, self-contained test case:
public record MyRecord(String value) {
public static void main(String[] args) throws Exception {
Jankson jankson = Jankson.builder().build();
MyRecord testValue = new MyRecord("test");
String serialized = jankson.toJson(testValue).toJson();
System.out.println("Original: " + testValue); // MyRecord[value=test]
System.out.println("Serialized: " + serialized); // { "value": "test" }
System.out.println();
MyRecord deserialized = jankson.fromJson(serialized, MyRecord.class);
System.out.println("Original: " + testValue); // MyRecord[value=test]
System.out.println("Deserialized: " + deserialized); // null
}
}
Thank you for the test case!
Records have definitely been on my mind lately.
I think we're going to have to have another breaking-changes version, because support requires some methods not available in java <14. Either that or some kind of live-detection mechanism that loads an extra class to handle it, which is a mess. I'll keep it in mind.
I'm happy to report that this is finally addressed in 2.0 alpha 3! Records will automatically be created using their canonical constructors, and json types constrained to the record component types. I'm leaving #50 up till I have Comment and SerializedName fully dialed in