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

Global Settings jsonb

Open Jamel-jun opened this issue 2 years ago • 4 comments

I want to DateFormat Global Settings. It seems that it cannot work. At present, I don't know where to start. I don't want to set them one by one through annotations to see if there is a global solution. I just got started and lack this part of knowledge. Please help me.

@ApplicationScoped
class JsonbCustomizer : JsonbConfigCustomizer {
    override fun customize(config: JsonbConfig?) {
        config ?: return
        config.withDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA)
        config.withNullValues(true)
        config.withFormatting(true)
    }
}

This is not currently working.

The last question is how to serialize and deserialize graphql. I have some features that need to be further understood.

Jamel-jun avatar May 29 '23 06:05 Jamel-jun

To register a custom JsonbConfig, follow the instructions in the documentation: https://smallrye.io/smallrye-graphql/2.2.0/custom-json-deserializers/ - specifically you need to add an EventingService for that. Will this work for you?

The last question is how to serialize and deserialize graphql. I have some features that need to be further understood.

Not sure what you mean. The engine uses JSON-B with the config that you may optionally provide for it, otherwise it uses the default settings.

jmartisk avatar May 29 '23 06:05 jmartisk

To register a custom JsonbConfig, follow the instructions in the documentation: https://smallrye.io/smallrye-graphql/2.2.0/custom-json-deserializers/ - specifically you need to add an EventingService for that. Will this work for you?

The last question is how to serialize and deserialize graphql. I have some features that need to be further understood.

Can EventingService act on the global.

Not sure what you mean. The engine uses JSON-B with the config that you may optionally provide for it, otherwise it uses the default settings.

What is the default setting? I did not see that the two methods are Jsonb.toJson or jsonb.fromJson. How is it serialized or deserialized? How can I modify it to overwrite the default settings.

Jamel-jun avatar May 29 '23 07:05 Jamel-jun

The default JsonbConfig is created like this: https://github.com/smallrye/smallrye-graphql/blob/2.2.0/server/implementation/src/main/java/io/smallrye/graphql/json/JsonBCreator.java#L73 That can be overridden per class via the EventingService. The JsonB object for a particular domain class is returned by https://github.com/smallrye/smallrye-graphql/blob/2.2.0/server/implementation/src/main/java/io/smallrye/graphql/json/JsonBCreator.java#L54 and then used during executions.

Yeah hmm, from looking at the code it seems we might be missing the option to override the global settings, not per-class. Perhaps we should add it...

jmartisk avatar May 29 '23 10:05 jmartisk

Ok, thanks for your answer. Will we include that later.

Jamel-jun avatar May 29 '23 12:05 Jamel-jun