Let's say I have Java classes that looks like this:
public class A {
public String name;
public B b;
}
public class B {
public int foo;
public String bar;
}
I want to serialize an instance of A
into JSON. I am going to use the ObjectMapper
class from Jackson:
A a = new A(...);
String json = new ObjectMapper().writeValueAsString(a);
Using this code, my JSON would look like this:
{
"name": "MyExample",
"b": {
"foo": 1,
"bar": "something"
}
}
Instead, I want to annotate my Java classes so that the generated JSON will instead look like this:
{
"name", "MyExample",
"foo": 1,
"bar": "something"
}
Any ideas?