yasson icon indicating copy to clipboard operation
yasson copied to clipboard

don't let unresolved proxies cancel json-processing

Open nimo23 opened this issue 6 years ago • 3 comments
trafficstars

I get this error when converting object to json-string with json-b:

javax.json.bind.JsonbException: Internal error: failed to lazily initialize a collection of role: test.Task.logs, could not initialize proxy - no Session

Task is a JPA Entity having logs-property as a lazy defined relationship, thus it's a proxy. I dont bother to include logs-property within json string.

Json-B should treat unresolvable proxies as null values by default instead of not generating a json-string and rethrowing exception.

nimo23 avatar Aug 10 '19 11:08 nimo23

hi @nimo23, can you include the full stack trace of the error, and also include an example of the JPA entity class being used here?

aguibert avatar Aug 10 '19 20:08 aguibert

hi, this is the full stacktrace - only one line of error message and no json string output.

The code which produces the error:

// because I used LAZY instead of EAGER
@OneToMany(mappedBy = "test", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private Set<Task> tasks;

If I use EAGER, Json-B works but with LAZY Json-B fails. So Json-B has problems with unresolvable proxies - it should return null for such props instead of breaking and rethrowing..

nimo23 avatar Aug 11 '19 00:08 nimo23

we might be able to add a special-case in Yasson where we automatically ignore certain JPA entity proxy methods.

Could you please upload a a dump of all of the:

  • methods on your entity class at runtime by using theEntity.getClass().getMethods()
  • fields on your entity class at runtime by using theEntity.getClass().getFields()

aguibert avatar Aug 11 '19 03:08 aguibert