projectlombok / lombok

Very spicy additions to the Java programming language.
https://projectlombok.org/
Other
12.93k stars 2.4k forks source link

[FEATURE] Add @ToJson and @FromJson Annotations for Automatic JSON Serialization and Deserialization #3739

Closed abdelhak-zaaim closed 2 months ago

abdelhak-zaaim commented 2 months ago

I would like to propose an enhancement to Lombok by introducing two new annotations: @ToJson and @FromJson. These annotations would automatically generate methods for JSON serialization and deserialization in a class, streamlining the process of converting objects to and from JSON. This feature would reduce the need for external libraries or manual implementations in Java classes.

@ToJson @FromJson public class MyClass { private String field1; private int field2; }

Expected Behavior:

Proposed Method Signatures:

  1. String toJson();
  2. static MyClass fromJson(String json);

Benefits:

janrieke commented 2 months ago

That has been suggested and denied several times. This feature is out of scope for Lombok, and there are several frameworks that can do it much better than Lombok could ever do.

See the other issues for more details.