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

Access to GSON configuration or "natural" joda-time types serialization out-of-the-box #14

Open
kozlovda opened this issue Mar 21, 2015 · 2 comments

Comments

@kozlovda
Copy link

Hi guys, great lib! :) Loving it!

Still there is an issue I'm facing every day which seems to have an easy solution.

Summary

Basically all I need is to be able to apply configuration to private GSON instance used internally. OR at least to make GSON builder to check if Joda-Time type adapters are available and auto-register them.

Use case

We use Joda-Time date types extensively in our services (well, primarily org.joda.time.DateTime).

When serialized by internal Shazamcrest GSON instance, it becomes a pages-long JSON structure that's really hard to read. Something like this:

Expected: {
  "createdAt": {
    "iMillis": 1426947578639,
    "iChronology": {
      "iBase": {
        "iBase": {
          "iBase": {
            "iMinDaysInFirstWeek": 4
          }
        },
        "iParam": {
          "iZone": {
            "iTransitions": [
              -9223372036854775808,
              -2717640000000,
              -1633269600000,
              -1615129200000,
              -1601820000000,
              -1583679600000,
              -880207200000,
              -769395600000,
...

And even worse: due to some bug in my IDE (IntelliJ IDEA) it puts into infinite loop on attempt to parse mismatch. Disclaimer: this is clearly IDE bug, not of library.

Feature Request

So it would be wonderful if we could just have some access to the GSON builder configuration. E.g. similar to ValueGenerators registration as implemented here: https://github.com/orien/bean-matchers#generating-property-values

Alternatively, having lib checking if there are Joda DateTime classes available and register this or this would be just fine.

Thanks in advance!

@nieldw
Copy link

nieldw commented Sep 25, 2015

@kozlovda I totally agree. Why don't you propose a pull request for this?

@roloreaper
Copy link

@kozlovda @nieldw
Can we add a Static method to the GsonProvider.registerCustomTypeAdapter();
This will allow a person to register one or more TypeAdapters that will be added GsonBuilder

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

3 participants