Java – Jackson – required property?

I use Jackson's readvalue () method on the object mapper to read from the JSON file and convert it into my java object

For example

mapperObject.readValue( node,MyTargetClass.class )

Are there any comments that can be set on mytargetclass to enforce the required properties? For example, if I have a JSON object with attributes ABC, def and GHI, and my JSON is

{
  "ABC" : "somevalue"
  "DEF" : "someothervalue" 
}

I want it to fail in some way. If it contains ABC, def and GHI, it can only succeed on readvalue

Solution

Jackson does not include validation, which is design (i.e. considered out of scope) However, the implementation of bean validation API is usually used The benefit of this is the decoupling between data format processing and validation logic This is the framework used by the dropwizard, and this is the direction jax-rs (such as Jersey) is taking for jax-rs 2.0

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>