Giter Club home page Giter Club logo

Comments (7)

swankjesse avatar swankjesse commented on July 21, 2024

Interesting. What I like is that we have some tech that makes this relatively straightforward.

from moshi.

NightlyNexus avatar NightlyNexus commented on July 21, 2024

@adriancole
Will JsonReader.readJsonValue() now do what you want?

from moshi.

codefromthecrypt avatar codefromthecrypt commented on July 21, 2024

from moshi.

codefromthecrypt avatar codefromthecrypt commented on July 21, 2024

actually another glitch is quoted numbers.. In a perfect world, I could snap off the leaf and the poke at it. Even without this change, it is still fine. Thanks though!

from moshi.

NightlyNexus avatar NightlyNexus commented on July 21, 2024

Oh, cool! Thank you for clarifying for me.
This seems straightforward to implement now.

I'll try it out this weekend and see if it's something others want to support.

Edit: realized it was easier than I thought; PR below.

from moshi.

NightlyNexus avatar NightlyNexus commented on July 21, 2024

Btw, the alternative is to delegate to the built-in adapters to do the conversions for you (because JsonAdapter.fromJsonValue creates the JsonValueReader).

final JsonAdapter<Double> doubleDelegate;
final JsonAdapter<Long> longDelegate;
fromJson(JsonReader reader) {
  Map<String, Object> object = reader.readJsonValue();
  String type = object.get("type");
  Object value = object.get("value");
  switch (type) {
    case I64:
      value = longDelegate.fromJsonValue(value);
      break;
    case DOUBLE:
      value = doubleDelegate.fromJsonValue(value);
      break;
    default:
      throw new JsonDataException("Unknown type: " + type);
  }
}

from moshi.

swankjesse avatar swankjesse commented on July 21, 2024

Nice. I think we have everything we need for this.

from moshi.

Related Issues (20)

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.