Is there a way using Jackson JSON Processor to do custom field level serialization? For example, I'd like to have the class
public class Person {
public String name;
public int age;
public int favoriteNumber;
}
serialized to the follow JSON:
{ "name": "Joe", "age": 25, "favoriteNumber": "123" }
Note that age=25 is encoded as a number while favoriteNumber=123 is encoded as a string. Out of the box Jackson marshalls int
to a number. In this case I want favoriteNumber to be encoded as a string.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…