lukas-krecan / JsonUnit

Compare JSON in your Unit Tests
Apache License 2.0
879 stars 115 forks source link

Picking gson instance #577

Open nickarls opened 1 year ago

nickarls commented 1 year ago

The documentation section "Selecting underlying library" mentions how to pick gson but how do you pick a specific instance (e.g. the one with the registered type adapters you need)?

lukas-krecan commented 1 year ago

Hi, it's currently not possible. But it should be possible to do something like this for Gson. Feel free to submit PR

nickarls commented 1 year ago

It would be handy to have it on API level. something like .withNodeFactory(MyGsonNodeFactory) with a default getGson() in GsonNodeFactory that returns new Gson() could be overridden. Or the GsonNodeFactory could have an abstract getGson() that the default implemention would implements as new Gson(). Could could have different ones for different tests...

(haven't checked if it's that applicable to the other serializers but I would assume that they all set up some context)

lukas-krecan commented 1 year ago

Sorry, I forgot about this issue. I will be reluctant to do something like you propose as it would mean making the NodeFactory and Node part of the public API/SPI hindering future refactorings.