Fields with capital letters in the beginning are not deserialised by jackson. java
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 217
- Forks
- 116
- PR merge metrics
- No merged PRs in 30d
Description
Hello. We have third party schema, where some fields begin with a capital letter.
As example:
type Query {
user(id: Int): User
}
type User {
ESIAPassport: String
firstName: String
}
Generated java class for User looks like:
public class User {
private String ESIAPassport;
private String firstName;
public String getESIAPassport() {
return ESIAPassport;
}
public void setESIAPassport(String ESIAPassport) {
this.ESIAPassport = ESIAPassport;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
}
We receive response like:
{
"data": {
"user": {
"firstName": "A",
"ESIAPassport": "1234"
}
}
}
If we try to read user object, then field ESIAPassport will not be deserialised by jackson, because jackson analyses setter name and expects json to contain field esiapassport.
ObjectMapper objectMapper = new ObjectMapper()
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
String response = """
{
"firstName": "A",
"ESIAPassport": "1234"
}
""";
User user = objectMapper.readValue(response, User.class);
assertEquals("A", user.getFirstName()); // ok
assertEquals("1234", user.getESIAPassport()); // fails
I suppose fix would be to add @JsonProperty annotation on getter or both getter and setter - looks like it doesn't matter for jackson.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated Java User class and the ObjectMapper example in the issue, focusing on how Jackson derives the property name from getESIAPassport and setESIAPassport. Reproduce the failing assertions with the ESIAPassport response, then verify that the generated class deserialises both fields while preserving the existing firstName behaviour.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100