question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`FAIL_ON_NULL_FOR_PRIMITIVES` failure does not indicate field name in exception message

See original GitHub issue
public class Test {

    private String type;
    private long num;

    @JsonCreator
    public Test(@JsonProperty(value = "type", required = true) String type,
                @JsonProperty(value = "num", required = true) long num) {
        this.type = type;
        this.num = num;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public long getNum() {
        return num;
    }

    public void setNum(long num) {
        this.num = num;
    }
}
ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true);

        try {
            String json = "{ \"type\" : \"number\", \"num\":null }";
            Test car = objectMapper.readValue(json, Test.class);

            System.out.println(car.getNum());
        } catch (MismatchedInputException ex) {
            ex.getPath().forEach(it -> System.out.println("field: " + it.getFieldName()));
        }

shows field: num but missing field in json

ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true);

        try {
            String json = "{ \"type\" : \"number\" }";
            Test car = objectMapper.readValue(json, Test.class);

            System.out.println(car.getNum());
        } catch (MismatchedInputException ex) {
            ex.getPath().forEach(it -> System.out.println("field: " + it.getFieldName()));
        }

shows nothing

Please add filed name and in this case.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
cowtowncodercommented, Sep 7, 2018

@raderio Actually, come to think of it bit more, I wonder if I was wrong. Reference mentions “field” or “key”, in Java context, and not in input source.

I’ll have to think bit more about this after all, since that being the case, it is not unreasonable it would be populated if there is sufficient information to do so.

0reactions
WellingRcommented, Dec 27, 2019

I also encountered this issue and wanted to report this. I have a potential fix ready and will create a PR soon

Read more comments on GitHub >

github_iconTop Results From Across the Web

jsf 2 - Include field name in error messages generated by ...
I do specify the label attribute - still doesn't get the field name through. (I'm using PrimeFaces 3.0.1 inputText rather than h:inputText, but...
Read more >
Kusto.Ingest errors & exceptions - Azure Data Explorer
Any error during the ingestion handling on the client side is indicated by a C# exception. Failures. KustoDirectIngestClient exceptions. While ...
Read more >
SQL error messages and exceptions - Oracle Help Center
The column <columnName> on table <tableName> has been modified by adding a not null constraint. 01504, The new index is a duplicate of...
Read more >
10.2 Exceptions - Racket Documentation
Creates an exn:fail:contract value and raises it as an exception. The name argument is used as the source procedure's name in the error...
Read more >
Error handling with DynamoDB - AWS Documentation
It also describes error messages and codes that are specific to Amazon DynamoDB. ... If you are not using an AWS SDK, you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found