1

I don't want to serialise any lazy object and tried a lot to get rid of this but no luck. Used

mapper.registerModule(new Hibernate5Module())

but this seems like loading any lazy object which i don't want. Have tried many possible ways which i got in net but no luck.

Only thing working for me is @JsonProperty(access = Access.WRITE_ONLY) but again it won't deserialise my data back which I don't want and also in some other condition I need this data back. I mean while I need this object on loaded data I need this object back.

I use:

  • Spring boot
  • Hibernate 5

Mapping in POJO:

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@Fetch(value = FetchMode.JOIN)
@JsonProperty(value = "parameterValues")
@JsonInclude(value=Include.NON_EMPTY, content=Include.NON_NULL)
private Set<FunctionalAreaParameterValueMaster> masterParameterValues;

in controller:

return new ResponseEntity<Data>(data, HttpStatus.OK);
Michał Ziober
  • 37,175
  • 18
  • 99
  • 146
Nayak
  • 99
  • 1
  • 7
  • I know you wrote that you searched internet but I must ask first. Have you seen: [jackson - do not serialize lazy objects](https://stackoverflow.com/questions/25906985/jackson-do-not-serialize-lazy-objects) and [Avoid Jackson serialization on non fetched lazy objects](https://stackoverflow.com/questions/21708339/avoid-jackson-serialization-on-non-fetched-lazy-objects). How it works when you have only single property like `private FunctionalAreaParameterValueMaster masterParameterValues`? Are you sure that you properly configured `ObjectMapper` and it is used during serialisation? – Michał Ziober Mar 06 '19 at 19:53
  • 1
    Yes done it ..... but problem is when am adding Hibernate5Module it is fetching my lazy objects from db which i dont want.I Just want it should not fetch the lazy objects and do not serialise my lazy data too.It should avoid those and serialise the remaining objects. – Nayak Mar 07 '19 at 07:25

0 Answers0