deserialization json abnormal -UnrecognizedPropertyException

Two months did not write the log, this time to catch the line item it is too busy, thank God or in the case of a shortage of personnel, the timely completion of the on-line. . .

---------------------------------------------------------------------

Access platform currently considering the logistics function, I added a complete courier saved to the database, it would not again queried, reducing the number of query functions.

But do take the return parameter json having trouble deserializing, an exception has been thrown.

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "name"。。。。。

 String json = "{\"name\":\"tom\",\"age\":24,\"cars\":[{\"brand\":\"bmw\",\"price\":740},{\"brand\":\"benz\",\"price\":600}]}";
        ObjectMapper mapper = new ObjectMapper();
        try {
            User user = mapper.readValue(json, User.class);
            System.out.println(user);
        } catch (IOException e) {
            e.printStackTrace ();
        }

Later, several tests concluded that the problem is when you want to json in the presence of a class entity is not an attribute, it will report this error, for example: json have name attributes, but there is no User name property, throw this exception . User object while sequentially no effect on serialization.

Guess you like

Origin www.cnblogs.com/runwithraining/p/12089004.html