Use @JsonValue:
public class User {
int id;
String name;
@JsonValue
public int getId() {
return id;
}
}
@JsonValue only works on methods so you must add the getId method. You should be able to skip your custom serializer altogether.