Netflix / Netflix/dgs-codegen

Fields with capital letters in the beginning are not deserialised by jackson. java

Open
#679 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.