Announcement Announcement Module
Collapse
No announcement yet.
Deserialization Problem from Json to Model Class Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Deserialization Problem from Json to Model Class

    I have created one application with Spring3 mvc,Hibernate3

    My configuration in Spring-servlet.xml, I have configured Json and JacksonMessageBean

    <bean
    class="org.springframework.web.servlet.view.Conten tNegotiatingViewResolver">
    <property name="mediaTypes">
    <map>
    <entry key="atom" value="application/atom+xml" />
    <entry key="html" value="text/html" />
    <entry key="json" value="application/json" />
    </map>
    </property>
    <property name="viewResolvers">
    <list>
    <bean class="org.springframework.web.servlet.view.UrlBas edViewResolver">
    <property name="viewClass"
    value="org.springframework.web.servlet.view.JstlVi ew" />
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />
    </bean>
    </list>
    </property>
    <property name="defaultViews">
    <list>
    <bean class="org.springframework.web.servlet.view.json.M appingJacksonJsonView" />
    </list>
    </property>
    </bean>
    <bean class="org.springframework.web.servlet.mvc.annotat ion.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
    <list>
    <bean id="jsonConverter" class="org.springframework.http.converter.json.Map pingJacksonHttpMessageConverter"/>
    </list>
    </property>
    </bean>
    -----

    I have used
    • jackson-core-asl-1.4.2.jar
    • jackson-mapper-asl-1.4.2.jar
    jars for configuration

    -------

    my POJO class

    @Entity
    @Table(name="tempTable")
    public class DevicePolling implements Serializable{

    public Integer getId() {
    return id;
    }

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

    public DeviceMaster getDeviceID() {
    return deviceID;
    }


    public void setDeviceID(DeviceMaster deviceID) {
    this.deviceID = deviceID;
    }

    public double getLattitude() {
    return lattitude;
    }

    public void setLattitude(double lattitude) {
    this.lattitude = lattitude;
    }

    public double getLongitude() {
    return longitude;
    }

    public void setLongitude(double longitude) {
    this.longitude = longitude;
    }
    @JsonSerialize(using=CustomDateFormatter.class)
    public Date getPollingTime() {
    return pollingTime;
    }

    public void setPollingTime(Date pollingTime) {
    this.pollingTime = pollingTime;
    }

    /**
    *
    */
    private static final long serialVersionUID = -7227603185161812526L;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="ID")
    private Integer id;


    @ManyToOne(cascade={CascadeType.ALL,CascadeType.ME RGE})
    @JoinColumn(name="device_id")
    private DeviceMaster deviceID;

    @Column(name="lattitude")
    private double lattitude;

    @Column(name="longitude")
    private double longitude;


    @Column(name="polling_tim")
    private Date pollingTime;


    }

    I have many to one relationship in this POJO..
    with URL I have passed json

    {
    "deviceID":"13",
    "lattitude":"37.09024",
    "longitude":"-95.71289"
    }

    ------
    and I got the Error like


    10:35:10,032 DEBUG DispatcherServlet:696 - Could not complete request
    org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of DeviceMaster
    out of VALUE_STRING token

    Is there any configuration missing? What should I do to solve this exception?
Working...
X