yasson
yasson copied to clipboard
don't let unresolved proxies cancel json-processing
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.
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?
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..
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()