How to detect trailing garbage using Jackson ObjectMapper

前端 未结 3 934
旧时难觅i
旧时难觅i 2021-01-20 00:43

Say I have a class

class A {
    public int x;
}

Then a valid json can be parsed as follows:

ObjectMapper mapper = new Obje         


        
3条回答
  •  说谎
    说谎 (楼主)
    2021-01-20 01:08

    As of Jackson version 2.9, there is now DeserializationFeature.FAIL_ON_TRAILING_TOKENS which can be used to achieve that:

    ObjectMapper objectMapper =
            new ObjectMapper().enable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS);
    

    See https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.9 and https://medium.com/@cowtowncoder/jackson-2-9-features-b2a19029e9ff

提交回复
热议问题