SalomonBrys / Kotson

Kotlin bindings for JSON manipulation via Gson
MIT License
709 stars 37 forks source link

Intermittently ignoring a custom type adaptor #13

Closed sanity closed 8 years ago

sanity commented 8 years ago

Here is my code:

    OutputStreamWriter(GZIPOutputStream(FileOutputStream("financials-0.0.1.json.gz"))).use {
        GsonBuilder()
                .registerTypeAdapter<Instant> {
                    serialize {
                        it.src.epochSecond.toJson()
                    }
                }
                .registerTypeAdapter<LocalDate> {
                    serialize {
                        it.src.toString().toJson()
                    }
                }
                .create().toJson(financials, it)

For some reason, it seems to be intermittently ignoring the Instant custom serializer and serializing an Instant field to {"seconds":1452211200,"nanos":0}

Sorry I can't reliably reproduce it, but can you think of any reason this could occur?

SalomonBrys commented 8 years ago

Sorry, I can't. Instant is a final class, so there should not be any need for registerTypeHierarchyAdapter. I've tried to reproduce this but I couldn't.

Are you using other means to configure GSon, such as the JsonAdapter annotation ?

sanity commented 8 years ago

A little confused, I used registerTypeAdapter, not registerTypeHierarchyAdapter ... ?

Are you using other means to configure GSon, such as the JsonAdapter annotation ?

Nope, the code you see is the only code in which I use Kotson or Gson in my codebase.

SalomonBrys commented 8 years ago

Well, I have tried to reproduce this, without any success. Indeed, you do not need registerTypeHierarchyAdapter, I was "thinking out loud".

I have no idea what's causing this, but I can't figure out any reason why the library would behave like that.

SalomonBrys commented 8 years ago

Hi, any update ? I've tried again all I could to reproduce, but couldn't...

sanity commented 8 years ago

No, haven't seen the problem since :(

On Thu, Mar 24, 2016, 10:53 Salomon BRYS notifications@github.com wrote:

Hi, any update ? I've tried again all I could to reproduce, but couldn't...

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/SalomonBrys/Kotson/issues/13#issuecomment-200898783

SalomonBrys commented 8 years ago

I'm closing the issue for now. If you encounter this behaviour again, feel free to reopen ;)

sanity commented 8 years ago

Roger wilco :)

On Thu, Mar 24, 2016 at 11:17 AM, Salomon BRYS notifications@github.com wrote:

I'm closing the issue for now. If you encounter this behaviour again, feel free to reopen ;)

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/SalomonBrys/Kotson/issues/13#issuecomment-200907171

Ian Clarke Blog: http://blog.locut.us/