Deserializing List<Serializable> object fails - using Spring 4.2.4 RestController and Jackson 2.5.4

776 views
Skip to first unread message

Luke Rahl

unread,
Jan 27, 2016, 4:18:30 PM1/27/16
to jackson-user
Deserializing List<Serializable> object fails - using Spring 4.2.4 RestController and Jackson 2.5.4.

I get the following error:

Unexpected failure: Could not read document: Can not construct instance of java.io.Serializable, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information\n at [Source: java.io.PushbackInputStream@408725ba; line: 1, column: 3071] (through reference chain: gov.sandia.generated.entities.eacontent.Ea[\"commonSections\"]->gov.sandia.generated.entities.eacontent.CommonSections[\"purpose\"]->gov.sandia.generated.entities.eacontent.Purpose[\"releaseReason\"]->java.util.ArrayList[0]->gov.sandia.generated.entities.eacontent.ReleaseReason[\"paragraph\"]->java.util.ArrayList[0]->gov.sandia.generated.entities.eacontent.Paragraph[\"content\"]->java.util.ArrayList[0]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of java.io.Serializable, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information\n at [Source: java.io.PushbackInputStream@408725ba; line: 1, column: 3071] (through reference chain: gov.sandia.generated.entities.eacontent.Ea[\"commonSections\"]->gov.sandia.generated.entities.eacontent.CommonSections[\"purpose\"]->gov.sandia.generated.entities.eacontent.Purpose[\"releaseReason\"]->java.util.ArrayList[0]->gov.sandia.generated.entities.eacontent.ReleaseReason[\"paragraph\"]->java.util.ArrayList[0]->gov.sandia.generated.entities.eacontent.Paragraph[\"content\"]->java.util.ArrayList[0])


Code for Paragraph:
package def.com.generated.entities.eacontent;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlMixed;
import javax.xml.bind.annotation.XmlType;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "paragraph", propOrder = {
   
"content"
})
public class Paragraph implements Serializable
{


   
private final static long serialVersionUID = -1L;
   
@XmlElementRef(name = "paragraph", namespace = "http://def.com/ea/schemas", type = JAXBElement.class, required = false)
   
@XmlMixed @org.mongodb.morphia.annotations.Serialized
   
protected List<Serializable> content;
   
@XmlAttribute(name = "ea-revision", required = true)
   
protected String eaRevision;
   
@XmlAttribute(name = "href")
   
protected String href;
   
@XmlAttribute(name = "id")
   
protected String id;
   
@XmlAttribute(name = "sequence")
   
protected String sequence;
   
@XmlAttribute(name = "para-status")
   
protected ParaStatus paraStatus;


   
/**
     * Default no-arg constructor
     *
     */

   
public Paragraph() {
       
super();
   
}


   
public Paragraph(final List<Serializable> content, final String eaRevision, final String href, final String id, final String sequence, final ParaStatus paraStatus) {
       
this.content = content;
       
this.eaRevision = eaRevision;
       
this.href = href;
       
this.id = id;
       
this.sequence = sequence;
       
this.paraStatus = paraStatus;
   
}


   
public List<Serializable> getContent() {
       
if (content == null) {
            content
= new ArrayList<Serializable>();
       
}
       
return this.content;
   
}


   
public String getEaRevision() {

       
return eaRevision;
   
}


   
public void setEaRevision(String value) {

       
this.eaRevision = value;
   
}


   
public String getHref() {

       
return href;
   
}


   
public void setHref(String value) {

       
this.href = value;
   
}


   
public String getId() {

       
return id;
   
}


   
public void setId(String value) {

       
this.id = value;
   
}


   
public String getSequence() {

       
return sequence;
   
}


   
public void setSequence(String value) {

       
this.sequence = value;
   
}


   
public ParaStatus getParaStatus() {

       
return paraStatus;
   
}


   
public void setParaStatus(ParaStatus value) {
       
this.paraStatus = value;
   
}


}


Do I need a custom mapper? If so, what?

Thanks!

Tatu Saloranta

unread,
Jan 27, 2016, 4:29:34 PM1/27/16
to jackso...@googlegroups.com
What would you expect to happen here? Given that `Serializable` does not give any useful indication of expected content type, the only direct improvement could be to consider this same as `List<Object>`, which would result in "untyped" elements (Java String from JSON String, Number from JSON Number etc).

-+ Tatu +-


--
You received this message because you are subscribed to the Google Groups "jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
To post to this group, send email to jackso...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Luke Rahl

unread,
Jan 30, 2016, 11:09:06 AM1/30/16
to jackson-user
I can get past it using ObjectMapper within a method, but trying to return it via a spring registered message handler doesn't seem to work.It seems to ignore the handler.

Tatu Saloranta

unread,
Jan 30, 2016, 7:41:53 PM1/30/16
to jackso...@googlegroups.com
One other thing to note is that type of JAXBElement.class is not supported by Jackson, either directly or by JAXB Annotations module -- it is XML-specific construct, and as such is not something that would map well with non-XML content. Not sure if that is relevant here (perhaps that is simply ignored), but thought I'll mention.

-+ Tatu +-

Reply all
Reply to author
Forward
0 new messages