What is a better way to set the value of the variable c in class Nested and then write the nested object to JSON instead of how it was done in the main method?
import lombok.Data;
@Data
public class Nested {
private A a;
@Data
public static class A {
private B b;
@Data
public static class B {
private int c;
}
}
}
import javax.json.bind.JsonbBuilder;
public class Main {
public static void main(String[] args) {
Nested nested = new Nested();
Nested.A a = new Nested.A();
Nested.A.B b = new Nested.A.B();
b.setC(123);
a.setB(b);
nested.setA(a);
System.out.println(JsonbBuilder.create().toJson(nested)); // Output: {"a":{"b":{"c":123}}}
}
}