简体   繁体   中英

YAML Jackson - NullPointerException when mapping an Integer property

Jackson 2.6.5

I try to map a YAML file to a POJO which contains Integer properties, when it reads the numeric properties, it throws:

com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException)

Funny thing is that if I single quote the numeric properties in the file, it parses them just fine (I guess it casts the String to Integers)

Is there any flag I have to set for Jackson to not try to cast numeric values or something?

Thank you

I meet the same problem.

To import YAMLFactory, I add the follow file in pom.xml,

        <dependency>
            <groupId>com.aceevo.ursus</groupId>
            <artifactId>ursus-example-application</artifactId>
            <version>0.2.7</version>
        </dependency>

but the correct one is the follow,

        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-yaml</artifactId>
            <version>2.9.2</version>
        </dependency>

so, I change this file and the problem dispear.

I found I was having the same issue.

I tried a simple yaml file in a separate project and things worked as expected (none of the fields no matter the type needed quoting!) so I'm not entirely sure why this might be happening.

However after a bit of fighting with the POM and the Yaml I think this is now working and I think it is because I cleaned up the full (production) yaml to remove the different types of quotes we were using - there was a mix of ' and " and I removed all quoting where possible and then things started working again.

You may also need to enable "ALLOW_UNQUOTED_FIELD_NAMES":

mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);

but I'm not convinced that is what made it work nor why given it is quoted values!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM