ObjectMapper objectMapper = new ObjectMapper();
JacksonAnnotationIntrospector implicitRecordAI = new JacksonAnnotationIntrospector() {
@Override
public String findImplicitPropertyName(AnnotatedMember m) {
if (m.getDeclaringClass().isRecord()) {
if (m instanceof AnnotatedParameter parameter) {
return m.getDeclaringClass().getRecordComponents()[parameter.getIndex()].getName();
}
if (m instanceof AnnotatedMember member) {
for (RecordComponent recordComponent : m.getDeclaringClass().getRecordComponents()) {
if (recordComponent.getName().equals(member.getName())) {
return member.getName();
}
}
}
}
return super.findImplicitPropertyName(m);
}
};
objectMapper.setAnnotationIntrospector(implicitRecordAI);