简体   繁体   中英

How to ignore object that I don't have with fasterxml jackson

I'm very new to java and android programming and in the application that I must maintain, we use fasterxml jackson to deserialize stuff from the server.

We handle must of the information (object) that we get from the server but some of the class we just don't want to handle them.

The problem is that each time the function getForObject from the RestTemplate receive one of these object that we just don't have in our code since we don't care, the library throw an exception like this:

org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Invalid type id 'com.xxxx.sam.common.sync.SongImageMappingSyncInfo' (for id type 'Id.class'): no such class found (through reference chain: [Ljava.lang.Object[][1]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: 

I have tried to ignore this with the property "FAIL_ON_UNKNOWN_PROPERTIES" to false but it doesn't change anything since it's not a property that I want to ignore, but an object completely...

Anybody know a way to skip these exception?

Thanks!

I always have this annotation above my objects which I want to deserialize:

@JsonIgnoreProperties(ignoreUnknown = true)
public class ClassToBeDeserialized() {
}

There doesn't seems to be a way to do this by design. It's kind of weird to receive a json object and ignore it. It's possible to ignore properties but to do so, your object must exist.

So what we did is to create the object in our code and we ignore it once it's deserialized.

Not pretty but it work.

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