I have a class where employeeDetails
is being read from a data store as json string.
public class Employee {
private String name;
@JsonProperty("employeeDetails")
@JsonSerialize(???)
private String employeeDetailsBlob;
// getters and setters
}
Now I want to return employeeDetails(dynamic type) as an object in my response. I have changed the name using @JsonProperty
and all the examples I have is for using @JsonSerialize(using = Employee.class)
.
So my response should look like this
{name: "foo", employeeDetails: { age: 21 }}
What I am getting is
{name: "foo", employeeDetails: "{ age: 21 }"}
I can add @JsonSerialize
to my class but then I have to handle all the fields myself and do something like this in the overridden method.
jgen.writeFieldName("employeeDetails");
SerializedString serializedString = new SerializedString(empl.getEmployeeDetailsBlob());
jgen.writeRawValue(serializedString);
Is there a way I can do it using annotations and that too only on the field I want to change from json string to json object.