smallrye-graphql icon indicating copy to clipboard operation
smallrye-graphql copied to clipboard

Dependency on yasson

Open t1 opened this issue 10 months ago • 3 comments

I just found the following code in RequestImpl that necessitates the dependency on yasson, which we should get rid of.

try (Jsonb jsonb = JsonbBuilder.create()) {
    JsonStructure struct = ((JsonBinding) jsonb).toJsonStructure(v);
    varBuilder.add(k, struct);
} catch (Exception ignore) {
}

Why is this not simply varBuilder.add(k, jsonb.toJson(v)); and why is the exception ignored?

If there is a valid reason, this deserves a comment. Anyone any idea? @hogmuzzle maybe?

t1 avatar Apr 23 '24 08:04 t1

Sorry, I meant varBuilder.add(k, Json.createReader(new StringReader(jsonb.toJson(v))).read());

If this is about performance, has anybody measured that? I think the JDK might very well be able to inline this.

t1 avatar Apr 23 '24 15:04 t1

We bring in Yasson anyway so I guess using its classes wasn't considered a problem, but if we can remove that, then why not. I'm not sure how often that branch is used though - if it's a complex Json object, that's caught already by else if (v instanceof JsonValue) no?

jmartisk avatar Apr 23 '24 16:04 jmartisk

We bring in Yasson anyway so I guess using its classes wasn't considered a problem, but if we can remove that, then why not.

It's also a dependency in the client/implementation module, but it's not used anywhere. Maybe we should make it optional or even remove it: BYOJB - bring your own JsonB 😁 In the server, it's only a test dependency.

I'm not sure how often that branch is used though - if it's a complex Json object, that's caught already by else if (v instanceof JsonValue) no?

That catches the JsonValue parameters, but that final else is for arbitrary Java objects.

t1 avatar Apr 24 '24 05:04 t1