7

I've have issues deserializing nested json data. I am using Ormlite to persist the data and a combination of Spring/Jackson(2) to fetch the data. Collections/lists of objects must be of the ForeignCollection interface before Ormlite will persist it. I've read several other Stackoverflow posts (1, 2, 3), but non of them has a clear solution.

Here is some of my code:

@ForeignCollectionField(eager = true)
@JsonProperty("images")
private ForeignCollection<Image> images;

I've tried adding @JsonDeserialize(as=BaseForeignCollection.class) without any luck. Changing ForeignCollection to Collection will make Jackson happy and parse the data, but then it won't hit the database.

Any ideas?

Community
  • 1
  • 1
tougher
  • 499
  • 1
  • 3
  • 13
  • Unfortunately I have not got access to the android libs or the `@ForeignCollectionFields`. If I interpret your problem correctly you have trouble deserializing the `ForeignCollection` as a *normal* collection. You can *force* the behaviour of Jackson deserialization by the `@JsonFormat` annotation. So, what happens if you add this to your field? `@JsonFormat(shape = JsonFormat.Shape.ARRAY)` – wassgren Dec 26 '14 at 12:03
  • Can you please provide your parent and child model class – ramji Nov 17 '16 at 13:35

1 Answers1

0

ForeignCollection is an interface, so serialization will not be possible. You should use a class implementing it, or just @JsonIgnore that field and add a regular List just for serialization/deserialization purposes.

Fco P.
  • 2,486
  • 17
  • 20