Coder Social home page Coder Social logo

moshi-gson-interop's Issues

Add examples

  • auto-value-gson/auto-value-moshi
  • Handling custom adapters/factories

Add `@JsonAdapter` annotation checker

Similar to Moshi's @JsonClass checker, but for GSON

/** Checks for classes annotated with GSON's [JsonAdapter] annotation. */
private class JsonAdapterAnnotationChecker : ClassChecker {
  override fun serializerFor(rawType: Class<*>): Serializer? {
    if (rawType.isAnnotationPresent(JsonAdapter::class.java)) {
      return Serializer.GSON
    }
    return null
  }
}

Add builder API

This would allow for some similar logic to how gson and moshi builders are done.

// Simple case
moshi.interopWith(gson)

// Advanced case
moshi.interopBuilder(gson)
  .addMoshiType(TypeA::class.java) // with reified extensions
  .addGsonType(TypeB::class.java)
  .addMoshiFactory(TypeAFactory::class.java) // take a moshi adapter factory. If it returns non-null, it's a moshi type
  .addGsonFactory(TypeBFactory::class.java)
  .addClassChecker(...)

Then in a conventional setup where someone is maybe wiring a multibinding set of adapters, they can easily add the same types

Another idea is to take JsonAdapter/TypeAdapter methods directly and resolve their generics with reflection to indicate their type?

Reevaluate complete instance requirement

I think it should be fine to allow later newBuilder()'d instances because they would just further delegate to any adapters added later, but we should test this.

Incompatible with `JsonTreeWriter`

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.