Skip to content

Using different Decoder / Encoder of same type at a same time #310

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

Closed
ndhcoder opened this issue Jan 24, 2022 · 2 comments
Closed

Using different Decoder / Encoder of same type at a same time #310

ndhcoder opened this issue Jan 24, 2022 · 2 comments

Comments

@ndhcoder
Copy link

Hello everyone,

Can I using different Decoder / Encoder of same type at a time ?

Example:
I have a API for export/import a data of class X:
{ "name": "ndhcoder", "age": 18 }

I need optimize storage so I'm using my customize decoder / encoder for minify field name of data to
{ "a": "ndhcoder", "b": 18 }

But in others API, X must be in a normal format:
{ "name": "ndhcoder", "age": 18 }

If I register decoder / encoder type at start time, I can't do both features. If I register decoder / encoder at the start time of each API, seem very confuse on multithreading, How do I resolve this problem ?
Thanks all

@ndhcoder ndhcoder changed the title Using different Decoder / Encoder of same type at a time Using different Decoder / Encoder of same type at a same time Jan 24, 2022
@svobol13
Copy link
Collaborator

@ndhcoder Hi, can you please share what was the resolution of the issue?

@ndhcoder
Copy link
Author

ndhcoder commented Jan 25, 2022

@ndhcoder Hi, can you please share what was the resolution of the issue?

JsonStream cache the Config object that extends EmptyExtension class (I will implement method createEncoder / Decoder for this config if I need my customize encoder/decoder) inside a ThreadLocal, So I just need create an Config and then pass it into JsonStream.seralize(config, object). By default, on each thread, JsonStream using same instance Config if not specified, so If I create one then other thread not side effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants