I am a Java novice using Jackson to serialise my object into XML. I need to format my String values by wrapping them in HTML paragraph tags. I have tried using a @JsonFormat
annotation but without success. My pseudo(code) is below:
package mypackage;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
public class MyClass {
// I want to find a pattern that will serialise text as <p>{string value of text}</p>
@JsonFormat(shape = Shape.STRING, pattern = "<p>{text}</p>") // can I do something like this?
String text;
public MyClass(MyOtherClass otherClass) {
this.text = otherClass.text;
}
}
I can't find any documentation on how to format pattern
to achieve what I want. Is using @JsonFormat
the wrong approach here?
You can create json getter and setter and then process field with your custom logic: