How do I use different names for serialization and deserialisation when using records?
java
public record testRecrd(@JsonProperty("foo bar") String fooBar){}
json
{
foo bar : "test"
}
Can I modify this record or is there any modifier I can use so when I deserialise the record I get
{
fooBar : "test"
}
2
Answers
Fixed using @JsonAlias as suggested in the accepted answer
Json returns:
You need to use
@JsonAlias
for deserialization:Jackson will first search for
foo bar
and only if it’s missing forfooBar
.