question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make it compatible with Retrofit

See original GitHub issue

I am having issues using this library with Retrofit and GSON.

Since some of the classes, like ZoneId are abstract and GSON can’t create them, I am getting exceptions on Retrofit when I try do deserialize my webservice JSON response.

It would be great to have an adapter that could be plugged into Retrofit to provide GSON the ability to deal with this library.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
JakeWhartoncommented, Jan 22, 2018
public @Rfc1123 OffsetDateTime createdAt;
public final class ModelAdapters {
  @FromJson //
  public @Rfc1123 OffsetDateTime rfc1123OffsetDateTimeFromJson(String value) {
    return OffsetDateTime.parse(value, RFC_1123_DATE_TIME);
  }

  @ToJson //
  public String rfc1123OffsetDateTimeToJson(@Rfc1123 OffsetDateTime value) {
    return RFC_1123_DATE_TIME.format(value);
  }
}
Moshi moshi = new Moshi.Builder() //
    .add(new ModelAdapters()) //
    .build();

// ...

.addConverterFactory(MoshiConverterFactory.create(moshi)) //
1reaction
JakeWhartoncommented, Jan 5, 2018

If you’re using Retrofit you’re using OkHttp which uses Okio which is what Moshi uses which means there’s no intermediate byte[] copies between layers so it’s faster. Most Gson vs. Moshi benchmarks either deal with Strings where it’s slower or actually use a real network where the network behavior contributes instability to the timings.

I can provide example Moshi adapters when I get home.

On Thu, Jan 4, 2018, 9:18 PM feinstein notifications@github.com wrote:

When I was searching for JSON solutions I decided to not use Moshi because it appeared to be 2x slower than GSON, at least from this benchmark: https://medium.com/@IlyaEremin/android-json-parsers-comparison-2017-8b5221721e31

Maybe the benchmark was flawed?

I will try Moshi then, if it fixes my issue I can cope with the slower performance. Thank you for the recommendation Jake!

— You are receiving this because you modified the open/close state.

Reply to this email directly, view it on GitHub https://github.com/JakeWharton/ThreeTenABP/issues/67#issuecomment-355455409, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEaESw9FF__g56DfZ__JH4l1mhuBLks5tHYaSgaJpZM4RTQvu .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Consuming APIs with Retrofit | CodePath Android Cliffnotes
This library makes downloading JSON or XML data from a web API fairly straightforward. Once the data is downloaded then it is parsed...
Read more >
Using Retrofit 2.x as REST client - Tutorial - Vogella.com
Create an Android application with the name Retrofit Github . Use com.vogella.android.retrofitgithub as the top level package name and use the empty template....
Read more >
Retrofit - Square Open Source
A type-safe HTTP client for Android and Java.
Read more >
Retrofit Android Example Tutorial - DigitalOcean
Retrofit is type-safe REST client for Android and Java which aims to make it easier to consume RESTful web services.
Read more >
Simple GET request using Retrofit in Android - Section.io
Simple GET request using Retrofit in Android · Step 1 – Create a new Android studio project · Step 2 – Adding retrofit...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found