Jackson ObjectMapper Conflicting Setter Definitions (Android.Graphics.Bitmap)

I have this method:

public static Response deserializeResponse(String jsonResponse) throws JsonParseException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); try{ return mapper.readValue(jsonResponse, Response.class); }catch(JsonParseException e){ e.printStackTrace(); }catch(JsonMappingException e){ e.printStackTrace(); }catch(IOException e){ e.printStackTrace(); } return null; } 

Here is the Answer class:

 public static class Response { public String RequestType; public Data data; public void SetRequestType(String requestType) { this.RequestType = requestType; } @JsonIgnore @JsonProperty("data") public void SetData(Data data) { this.data = data; } public Response(){ data = new Data(); } public static class Data { public String Status; public String ErrorCode; public int versionCode; public String Expiry; public String ProductSKU; public String Email; public String Birthday; public String PictureUrl; public String Pin; public List<PhoneNumber> Numbers = new ArrayList<PhoneNumber>(); public int IdTransaction; public int SubProductId; public List<Performer> Performers = new ArrayList<Performer>(); public Client Client; public Data() {} } } 

Here is a call to another class:

 Response rep = JsonOperation.deserializeResponse(jsonString); 

I run this code on a device using Android 2.3.6 and everything works fine. When I run this code on my Galaxy Note 3 or S4, I have segment errors. Here is the log:

 W/System.errīš• com.fasterxml.jackson.databind.JsonMappingException: Conflicting setter definitions for property "imagePath": android.graphics.Bitmap#setImagePath(1 params) vs android.graphics.Bitmap#setImagePath(1 params) 03-21 15:51:54.373 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:269) 03-21 15:51:54.373 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244) 03-21 15:51:54.373 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:143) 03-21 15:51:54.373 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.DeserializationContext.findContextualValueDeserializer(DeserializationContext.java:325) 03-21 15:51:54.373 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.std.StdDeserializer.findDeserializer(StdDeserializer.java:633) 03-21 15:51:54.373 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:427) 03-21 15:51:54.373 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:295) 03-21 15:51:54.373 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244) 03-21 15:51:54.373 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:143) 03-21 15:51:54.373 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.DeserializationContext.findContextualValueDeserializer(DeserializationContext.java:325) 03-21 15:51:54.373 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.createContextual(CollectionDeserializer.java:147) 03-21 15:51:54.373 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.createContextual(CollectionDeserializer.java:23) 03-21 15:51:54.373 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.DeserializationContext.findContextualValueDeserializer(DeserializationContext.java:329) 03-21 15:51:54.373 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.std.StdDeserializer.findDeserializer(StdDeserializer.java:633) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:427) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:295) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:143) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.DeserializationContext.findContextualValueDeserializer(DeserializationContext.java:325) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.std.StdDeserializer.findDeserializer(StdDeserializer.java:633) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:427) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:295) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:143) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:342) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:2895) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2789) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:1943) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.francovoyance.JsonOperation.deserializeResponse(JsonOperation.java:321) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.francovoyance.HttpOperation$HttpPostRequest.doInBackground(HttpOperation.java:125) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.francovoyance.HttpOperation$HttpPostRequest.doInBackground(HttpOperation.java:69) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at android.os.AsyncTask$2.call(AsyncTask.java:287) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at java.util.concurrent.FutureTask.run(FutureTask.java:234) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at java.lang.Thread.run(Thread.java:841) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• Caused by: java.lang.IllegalArgumentException: Conflicting setter definitions for property "imagePath": android.graphics.Bitmap#setImagePath(1 params) vs android.graphics.Bitmap#setImagePath(1 params) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder.getSetter(POJOPropertyBuilder.java:196) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.filterBeanProps(BeanDeserializerFactory.java:614) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.addBeanProps(BeanDeserializerFactory.java:522) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:267) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:171) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:388) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:264) 03-21 15:51:54.383 15204-15218/com.francovoyance W/System.errīš• ... 36 more 

Here is the Json login from the server:

 private string CheckVersion(JObject jsonObject) { StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); using (JsonWriter writer = new JsonTextWriter(sw)) { writer.Formatting = Formatting.Indented; writer.WriteStartObject(); writer.WritePropertyName("RequestType"); writer.WriteValue("CheckVersion"); writer.WritePropertyName("data"); writer.WriteStartObject(); writer.WritePropertyName("Status"); string inVersion = (string)jsonObject["data"]["versionCode"]; string actualVersion = WebTV.Common.AppSettings.GetString("APP_VERSION", "1"); actualVersion = Convert.ToString((int)Convert.ToDouble(actualVersion)); if (inVersion.Equals(actualVersion)) { writer.WriteValue("Ok"); } else { writer.WriteValue("Error"); writer.WritePropertyName("versionCode"); writer.WriteRawValue(actualVersion); } writer.WriteEndObject(); } return sb.ToString(); } 

I searched and tried to find answers to this problem, but I did not find anything about setters in android.graphics.Bitmap ... I tried to use @JsonIgnore without any results. I need help to resolve an exception when I try to use mapper. Any help would be appreciated.

+7
java json android jackson
source share
1 answer

I just solved this problem (for me), although it seems like a workaround for these Samsung devices. I understand you mentioned that you tried the @JsonIgnore annotation, but I managed to solve my problem.

In my model, I only matched JSON with a small subset of the base model. However, in this base model, I had a list of another object model containing a bitmap. By adding @JsonIgnore to the list of models, the problem was resolved (although I did not match them and they should have been ignored).

I used the ObjectMapper function to ignore unused values, but it did not work on Samsung devices.

 ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); 

In the example below, the Profile object contains a bitmap, and I only map the name and age to JSON.

Example:

 public class A { private String name; private int age; @JsonIgnore private List<Profile> profiles; } 

If I had to guess, I would say that your Performer object above contains a bitmap, and if you do not match this, I would try and ignore List.

+9
source share

All Articles