Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible with JsonTreeWriter #22

Closed
ZacSweers opened this issue Nov 15, 2020 · 2 comments · Fixed by #25
Closed

Incompatible with JsonTreeWriter #22

ZacSweers opened this issue Nov 15, 2020 · 2 comments · Fixed by #25
Labels
bug Something isn't working

Comments

@ZacSweers
Copy link
Collaborator

When the incoming GSON JsonWriter is JsonTreeWriter, jsonValue() APIs will no longer work because GSON doesn't support writing raw JSON in this environment. Not sure if this is something we really can support, vs not allowing Moshi serializers to be preferred when we're in this condition. Not sure we can infer this ahead of time though.

@ZacSweers
Copy link
Collaborator Author

One idea could be to propose adding support for this in GSON via internal holder type, so that when it tries to convert it to string it just takes the raw byte out of this holder

@ZacSweers
Copy link
Collaborator Author

ZacSweers commented Nov 16, 2020

I found these but nothing promising

google/gson#1268
google/gson#1289
google/gson#1651

Put up a PR here google/gson#1819.

GSON seems mostly abandoned though so not optimistic about it getting reviewed/merged. Those that need this should probably either move away from using JsonElement APIs in their own custom adapters or creating a fork with the above change included.

I think it would be possible to replace the built-in JsonTreeWriter in a custom version (i.e. the one from my PR) + TypeAdapters.JSON_ELEMENT replacement with the PR changes, but hesitant to do that unless we have to though. I tried to implement it without upstream support, but hit a dead end due to Streams.java in gson eventually using its own hardcoded TypeAdapters.JSON_ELEMENT to write it in the end.

@ZacSweers ZacSweers added the bug Something isn't working label Nov 16, 2020
ZacSweers added a commit that referenced this issue Nov 18, 2020
Uses internal APIs but this library isn't stable anyway. This works around that issue until a fixed future version of GSON that properly supports jsonValue in JsonTreeWriter (if ever) by converting it manually to a `JsonElement` and writing it directly via its `JsonElement` `TypeAdapter`.

Resolves #22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant