2016-08-25 2 views
1

Ich habe eine CookingEvent.class, die eine Unterklasse von Event.class ist und die Vererbungsstrategie für den Hibernate ist @Inheritance (strategie = InheritanceType.JOINED). wenn ich versuche, eine Liste Objekte als get Antwort zu senden .Ichcom.fasterxml.jackson.databind.JsonMappingException: Objekt ist keine Instanz der deklarierenden Klasse

2016-08-25 11 unter Ausnahme ist immer: 49: 22,351 ERROR 11944 --- [nio-8189-exec-1] oaccC [. [. [/]. [servletContainer]: Servlet.service() für servlet [servletContainer] im Kontext mit Pfad [] hat Ausnahme ausgelöst [org.glassfish.jersey.server.ContainerException: com.fasterxml.jackson .databind.JsonMappingException: Objekt ist keine Instanz der Klasse zu erklären (durch Referenzkette: java.util.ArrayList [0] -> Object [] [ "eventId"])] mit Ursachen

java.lang.IllegalArgumentException: Objekt ist nicht eine Instanz von deklarierte Klasse bei sun.reflect.NativeMethodAccessorImpl.invoke0 (native Methode) bei sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) bei Sonne. reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) bei java.lang.reflect.Method.invoke (Method.java:497) um com.fasterxml.jackson.databind.ser.BeanPropertyWriter.get (BeanPropertyWriter.java: 726) bei com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField (BeanPropertyWriter.java:506) bei com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields (Bean SerializerBase.java:644) bei com.fasterxml.jackson.databind.ser.BeanSerializer.serialize (BeanSerializer.java:152)

@Entity 
@Table(name = "users") 
@JsonAutoDetect 
public class Users implements java.io.Serializable { 

    @JsonBackReference 
    private List<Event> eventByUser = new ArrayList<Event>(
      0); 

    @Id 
    @GeneratedValue 
    @Column(name = "USER_ID", unique = true) 
    public Long getUserId() { 
     return userIds; 
    } 
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "user") 
    @Fetch(FetchMode.JOIN) 
    @JsonInclude(JsonInclude.Include.NON_EMPTY) 
    @JsonIgnore 
    public List<Event> getEventByUser() { 
     return eventByUser; 
    } 
} 


    @Entity 
    @Table(name = "EVENT") 
    @Inheritance(strategy=InheritanceType.JOINED) 
    public class Event implements java.io.Serializable { 

     private Integer eventId; 

     @Id 
     @GeneratedValue 
     @Column(name = "COOKING_EVENT_ID", unique = true) 
     public Integer getEventId() { 
      return eventId; 
     } 
     private Users user; 

     @ManyToOne(fetch = FetchType.LAZY) 
    @Fetch(FetchMode.SELECT) 
    @JsonIgnore 
    @JsonInclude(JsonInclude.Include.NON_EMPTY) 
    @JoinColumn(name = "ASSIGNED_USER_ID", nullable = false) 
    @JsonManagedReference 
    public Users getUser() { 
     return user; 
    } 

     public void setEventId(Integer eventId) { 
      this.eventId = eventId; 
     } 



@Entity 
    @Table(name = "COOKING_REQUEST_EVENT") @PrimaryKeyJoinColumn(name="EVENT_ID") 
public class CookingRequestEvent extends Event implements java.io.Serializable { 

     //Other Variables along with setters and getters 

     } 

Ich habe einen Jersey-Controller, wie unten, die eine Liste zurückgibt

@GET 
     @Path("/cookingEventsByUser/{userId}") 
     @Produces({ MediaType.APPLICATION_JSON}) 
     public List<CookingEvent> getEventsById(@PathParam("userId") Long id) 
       throws JsonGenerationException, JsonMappingException, IOException { 
      List<CookingEvent> events = new ArrayList<CookingEvent>(); 
     events = cookingEventServices.getCookingEventsByUser(id); 

     } 

ich bin mit Frühlings-Stiefel + Jersey +

Antwort

0

Ausgabe überwintern wird aufgelöst.

Added

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include =As.PROPERTY, property = "data") 
@JsonSubTypes({ @Type(value = CookingEvent.class, name = "cookingEvent"), @Type(value = CookingRequestEvent.class, name = "cookingRequest") }) 
Verwandte Themen