Jackson JsonMappingException: Can not deserialize instance

Azhar92

I'm trying to convert my json data to a POJO object using Jackson. Here is the MainActivity and my POJO class code. I'm basically getting a JsonMappingException error. I have also attached the whole log.

MainActivity.java :

ObjectMapper mapper = new ObjectMapper();
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    try {
        List<Entries> results = mapper.readValue(new URL("http://collegewires.com/android/jacksoncw.json"), new TypeReference<List<Entries>>(){});
        for(int i=0;i<results.size();++i){
            System.out.println(results.get(i).getName());
            out = out + " ## " + results.get(i).getName();
            txt.setText("1111");
        }
    } catch (JsonParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();

    } catch (JsonMappingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();

    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Entries.java (this is the POJO)

package com.collegewires.jackson;

public class Entries {
public Entries(){
}

private String id, name, email, address, gender;
private Phone phone;

public Phone getPhone() {
    return phone;
}

public void setPhone(Phone phone) {
    this.phone = phone;
}

public String getId() {
    return id;
}

public void setId(String id) {
    this.id = id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getAddress() {
    return address;
}

public void setAddress(String address) {
    this.address = address;
}

public String getGender() {
    return gender;
}

public void setGender(String gender) {
    this.gender = gender;
}

@Override
public String toString() {
    return "Entries:{id: " + id + ", name: " + name + 
                ", email: " + email + ", address: " + address + ", gender: " + gender + ", phone: " + phone + "}";
}

public class Phone {
    public Phone(){
    }
    public String  mobile, home, office;
    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getHome() {
        return home;
    }

    public void setHome(String home) {
        this.home = home;
    }

    public String getOffice() {
        return office;
    }

    public void setOffice(String office) {
        this.office = office;
    }

    @Override
    public String toString() {
        return "Phone:{mobile: " + mobile + ", home: " + home + 
                    ", office: " + office + "}";
    }
}


}

Now, I'm getting the following error in my log. Because of this, I'm unable to proceed with my work. Here is the log :

07-12 12:06:13.206: W/System.err(30593): 

com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
07-12 12:06:13.206: W/System.err(30593):  at [Source: http://collegewires.com/android/jacksoncw.json; line: 1, column: 1]
07-12 12:06:13.211: W/System.err(30593):    at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:575)
07-12 12:06:13.211: W/System.err(30593):    at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:569)
07-12 12:06:13.211: W/System.err(30593):    at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.handleNonArray(CollectionDeserializer.java:259)
07-12 12:06:13.211: W/System.err(30593):    at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:217)
07-12 12:06:13.211: W/System.err(30593):    at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:207)
07-12 12:06:13.211: W/System.err(30593):    at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:23)
07-12 12:06:13.211: W/System.err(30593):    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2888)
07-12 12:06:13.211: W/System.err(30593):    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2018)
07-12 12:06:13.211: W/System.err(30593):    at com.collegewires.jackson.MainActivity.onCreate(MainActivity.java:81)
07-12 12:06:13.211: W/System.err(30593):    at android.app.Activity.performCreate(Activity.java:5250)
07-12 12:06:13.211: W/System.err(30593):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
07-12 12:06:13.211: W/System.err(30593):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
07-12 12:06:13.211: W/System.err(30593):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2297)
07-12 12:06:13.211: W/System.err(30593):    at android.app.ActivityThread.access$700(ActivityThread.java:152)
07-12 12:06:13.211: W/System.err(30593):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1282)
07-12 12:06:13.211: W/System.err(30593):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-12 12:06:13.211: W/System.err(30593):    at android.os.Looper.loop(Looper.java:137)
07-12 12:06:13.211: W/System.err(30593):    at android.app.ActivityThread.main(ActivityThread.java:5328)
07-12 12:06:13.211: W/System.err(30593):    at java.lang.reflect.Method.invokeNative(Native Method)
07-12 12:06:13.211: W/System.err(30593):    at java.lang.reflect.Method.invoke(Method.java:511)
07-12 12:06:13.211: W/System.err(30593):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
07-12 12:06:13.211: W/System.err(30593):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
07-12 12:06:13.211: W/System.err(30593):    at dalvik.system.NativeStart.main(Native Method)
07-12 12:06:13.251: D/libEGL(30593): loaded /vendor/lib/egl/libEGL_POWERVR_SGX544_115.so
07-12 12:06:13.261: D/libEGL(30593): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX544_115.so
07-12 12:06:13.266: D/libEGL(30593): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX544_115.so
07-12 12:06:13.271: I/(30593): !@IMGSRV: DATE: 2013.04.23(11:19:33) | BUILDER: LSI3D | REVISION: e9cd1377d8225457ae40
07-12 12:06:13.346: D/OpenGLRenderer(30593): Enabling debug mode 0
07-12 12:06:31.521: W/IInputConnectionWrapper(30593): setComposingText on inactive InputConnection
VenomVendor
  1. Remove the Constructor in Entries & Phone

  2. GetEntries results = mapper.readValue(new URL("http://collegewires.com/android/jacksoncw.json"), GetEntries.class);

  3. Entries seems to be a parameter in your JSON.

GetEntries.java

package com.collegewires.jackson;

import java.util.List;

public class GetEntries{
    private List<Entries> entries;

    public List<Entries> getEntries(){
        return this.entries;
    }
    public void setEntries(List<Entries> entries){
        this.entries = entries;
    }
}

Entries.java

package com.collegewires.jackson;

import java.util.List;

public class Entries{
    private String address;
    private String email;
    private String gender;
    private String id;
    private String name;
    private Phone phone;

    public String getAddress(){
        return this.address;
    }
    public void setAddress(String address){
        this.address = address;
    }
    public String getEmail(){
        return this.email;
    }
    public void setEmail(String email){
        this.email = email;
    }
    public String getGender(){
        return this.gender;
    }
    public void setGender(String gender){
        this.gender = gender;
    }
    public String getId(){
        return this.id;
    }
    public void setId(String id){
        this.id = id;
    }
    public String getName(){
        return this.name;
    }
    public void setName(String name){
        this.name = name;
    }
    public Phone getPhone(){
        return this.phone;
    }
    public void setPhone(Phone phone){
        this.phone = phone;
    }
}

Phone.java

package com.collegewires.jackson;

import java.util.List;

public class Phone{
    private String home;
    private String mobile;
    private String office;

    public String getHome(){
        return this.home;
    }
    public void setHome(String home){
        this.home = home;
    }
    public String getMobile(){
        return this.mobile;
    }
    public void setMobile(String mobile){
        this.mobile = mobile;
    }
    public String getOffice(){
        return this.office;
    }
    public void setOffice(String office){
        this.office = office;
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Deserialization with Jackson: "org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of [projectname]."

From Dev

jsonMappingException org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token at

From Dev

Exception: "org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token"

From Dev

com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of org.springframework.data.domain.Sort out of START_ARRAY token

From Dev

com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize out of START_ARRAY token

From Dev

JsonMappingException: Can not deserialize instance of java.lang.Integer out of START_OBJECT token

From Dev

Convert JSON to Object throws JsonMappingException "Can not deserialize instance of class out of START_ARRAY token"

From Dev

JsonMappingException: Can not deserialize instance of java.lang.Integer out of START_OBJECT token

From Dev

JsonMappingException: Can not deserialize instance of java.util.List out of START_OBJECT token

From Dev

Can not deserialize instance of parseJason when using Jackson to parse the Json File

From Dev

Jackson JSON Can not construct instance of "About" : deserialize issue

From Dev

com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of : poja class no suitable constructor found

From Dev

JsonMappingException: Can not construct instance of CommonsMultipartFile

From Dev

Jackson Can not deserialize empty array

From Dev

com.fasterxml.jackson.databind.exc.MismatchedInputException: Can not deserialize instance of object out of START_ARRAY token

From Dev

Jackson Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token

From Java

com.fasterxml.jackson.databind.exc.MismatchedInputException: Can not deserialize instance of object out of START_ARRAY token - JAVA

From Dev

Can't deserialize a wrapped List with Jackson XmlMapper

From Dev

Why can't Jackson deserialize this JSON?

From Dev

Jackson can't deserialize JSON it serializes with enableDefaultTyping()

From Dev

RESTEasy with jackson causes serializing JsonMappingException

From Dev

RESTEasy with jackson causes serializing JsonMappingException

From Dev

Jackson + ProGuard: can't deserialize class that uses custom deserializer

From Dev

How can I get Jackson to deserialize into my own Array implementation

From Dev

Can't deserialize extended abstract class json using Jackson in Java

From Java

Jackson error: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token

From Dev

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of Object out of START_ARRAY token

From Dev

Deserialize JSONP with Jackson

From Dev

Deserialize List<Interface> with jackson

Related Related

  1. 1

    Deserialization with Jackson: "org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of [projectname]."

  2. 2

    jsonMappingException org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token at

  3. 3

    Exception: "org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token"

  4. 4

    com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of org.springframework.data.domain.Sort out of START_ARRAY token

  5. 5

    com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize out of START_ARRAY token

  6. 6

    JsonMappingException: Can not deserialize instance of java.lang.Integer out of START_OBJECT token

  7. 7

    Convert JSON to Object throws JsonMappingException "Can not deserialize instance of class out of START_ARRAY token"

  8. 8

    JsonMappingException: Can not deserialize instance of java.lang.Integer out of START_OBJECT token

  9. 9

    JsonMappingException: Can not deserialize instance of java.util.List out of START_OBJECT token

  10. 10

    Can not deserialize instance of parseJason when using Jackson to parse the Json File

  11. 11

    Jackson JSON Can not construct instance of "About" : deserialize issue

  12. 12

    com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of : poja class no suitable constructor found

  13. 13

    JsonMappingException: Can not construct instance of CommonsMultipartFile

  14. 14

    Jackson Can not deserialize empty array

  15. 15

    com.fasterxml.jackson.databind.exc.MismatchedInputException: Can not deserialize instance of object out of START_ARRAY token

  16. 16

    Jackson Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token

  17. 17

    com.fasterxml.jackson.databind.exc.MismatchedInputException: Can not deserialize instance of object out of START_ARRAY token - JAVA

  18. 18

    Can't deserialize a wrapped List with Jackson XmlMapper

  19. 19

    Why can't Jackson deserialize this JSON?

  20. 20

    Jackson can't deserialize JSON it serializes with enableDefaultTyping()

  21. 21

    RESTEasy with jackson causes serializing JsonMappingException

  22. 22

    RESTEasy with jackson causes serializing JsonMappingException

  23. 23

    Jackson + ProGuard: can't deserialize class that uses custom deserializer

  24. 24

    How can I get Jackson to deserialize into my own Array implementation

  25. 25

    Can't deserialize extended abstract class json using Jackson in Java

  26. 26

    Jackson error: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token

  27. 27

    com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of Object out of START_ARRAY token

  28. 28

    Deserialize JSONP with Jackson

  29. 29

    Deserialize List<Interface> with jackson

HotTag

Archive