profile
viewpoint
Jesse Wilson swankjesse Square, Inc. Waterloo, Ontario, Canada http://publicobject.com/

google/gson 18859

A Java serialization/deserialization library to convert Java Objects into JSON and back

JakeWharton/DiskLruCache 5495

Java implementation of a Disk-based LRU cache which specifically targets Android compatibility.

square/kotlinpoet 2530

A Kotlin API for generating .kt source files.

notnoop/java-apns 1770

Java Apple Push Notification Service Provider

JakeWharton/diffuse 1205

Diffuse is a tool for diffing APKs, AABs, AARs, and JARs

cashapp/misk 250

Microservice Kontainer

JakeWharton/RxJava2-Java6 72

An automated backport of RxJava 2 to support Java 6.

AlecStrong/sql-psi 62

An extendable parsing environment for sql which outputs PSI

cashapp/barber 61

Barber 💈 A type safe Kotlin JVM library for building up localized, fillable, themed documents using Mustache templating

jspecify/jspecify 50

An artifact of well-named and well-specified annotations to power static analysis checks.

issue closedsquare/moshi

How to parse fields with the same key but different values

This is driving me crazy. I spent the whole day and I still cannot figure out the issue I'm facing.

Our backend sends a json response that can contain different values for the same key every time.

Example of First variation:

{
  "title": "2",
  "profile_image": {
    "profile_image_id": "4581542",
    "sized": "media/up/2020/48/460e689e286ca46b1006b62269ee21a22b6bdabf2496506e34e5d07c5d42c20f_user_photo_160674563705555.sized.JPG",
    "sized_w": "556",
    "sized_h": "555",
    "thumb": "media/up/2020/48/460e689e286ca46b1006b62269ee21a22b6bdabf2496506e34e5d07c5d42c20f_user_photo_160674563705555.thumb.JPG",
    "thumb_w": "90",
    "thumb_h": "90"
  },
  "profile": {
    "title": "2",
    "first_name": "John",
    "last_name": "Doe",
    "user_online_status": false
  }
}

And below is an another variation of the same response. Notice the profile_image field is now an Array type and user_online_status can also be a string or a boolean.

{
  "title": "2",
  "profile_image": [
    
  ],
  "profile": {
    "title": "2",
    "first_name": "John",
    "last_name": "Doe",
    "user_online_status": "0"
  }
}

How can I parse such responses using Retrofit and Moshi without creating extra model classes? Can I use a custom adapter Maybe? Could you give me an example? I tried to make an adapter of my own but didn't managed to get far

class SkipEmptyProfileAdapter {
    

    @FromJson
    fun fromJson(reader: JsonReader): UserProfileDataResponse? {
        val moshi = Moshi.Builder().build()

        reader.beginObject()
        while (reader.hasNext()) {
            if (reader.nextName() == "profile_image") {
                Timber.i("PROFILE IMAGE")
                val pls = reader.peek()
                if (pls == JsonReader.Token.BEGIN_ARRAY)
                    return null
            }
        }
        reader.endObject()
        return null
    }

}

Can you help me out?

closed time in 29 minutes

ThanosFisherman

issue commentsquare/moshi

How to parse fields with the same key but different values

Stack Overflow is the place for questions like this, this is a forum for bugs in Moshi.

That being said, it looks like you're moving in the right direction. A custom type adapter and peek() is the right way to deal with that kind of garbage. I'd recommend continuing down that path and handling the other possible cases, and head to Stack Overflow if you end up stuck on a specific part.

ThanosFisherman

comment created time in 29 minutes

issue openedsquare/moshi

How to parse fields with the same key but different values

This is driving me crazy. I spent the whole day and I still cannot figure out the issue I'm facing.

Our backend sends a json response that can contain different values for the same key every time.

Example of First variation:

{
  "title": "2",
  "profile_image": {
    "profile_image_id": "4581542",
    "sized": "media/up/2020/48/460e689e286ca46b1006b62269ee21a22b6bdabf2496506e34e5d07c5d42c20f_user_photo_160674563705555.sized.JPG",
    "sized_w": "556",
    "sized_h": "555",
    "thumb": "media/up/2020/48/460e689e286ca46b1006b62269ee21a22b6bdabf2496506e34e5d07c5d42c20f_user_photo_160674563705555.thumb.JPG",
    "thumb_w": "90",
    "thumb_h": "90"
  },
  "profile": {
    "title": "2",
    "first_name": "John",
    "last_name": "Doe",
    "user_online_status": false
  }
}

And below is an another variation of the same response. Notice the profile_image field is now an Array type and user_online_status can also be a string or a boolean.

{
  "title": "2",
  "profile_image": [
    
  ],
  "profile": {
    "title": "2",
    "first_name": "John",
    "last_name": "Doe",
    "user_online_status": "0"
  }
}

How can I parse such responses using Retrofit and Moshi without creating extra model classes? Can I use a custom adapter Maybe? Could you give me an example? I tried to make an adapter of my own but didn't managed to get far

class SkipEmptyProfileAdapter {
    

    @FromJson
    fun fromJson(reader: JsonReader): UserProfileDataResponse? {
        val moshi = Moshi.Builder().build()

        reader.beginObject()
        while (reader.hasNext()) {
            if (reader.nextName() == "profile_image") {
                Timber.i("PROFILE IMAGE")
                val pls = reader.peek()
                if (pls == JsonReader.Token.BEGIN_ARRAY)
                    return null
            }
        }
        reader.endObject()
        return null
    }

}

Can you help me out?

created time in an hour

issue closedsquare/kotlinpoet

How to judge whether the parameter of annotation is nullable?

val isNullable = parameterElement.asType().asTypeName().isNullable

When I do, it always returns null

closed time in an hour

plumcookingwine

issue openedsquare/kotlinpoet

How to judge whether the parameter of annotation is nullable?

val isNullable = parameterElement.asType().asTypeName().isNullable

When I do, it always returns null

created time in an hour

issue commentsquare/okio

okio-async module for Kotlin coroutines based asyncio

I like the AsyncDispatcher approach. I'm interested to play with it and see where complexities arise is a highly concurrent protocol like BitTorrent.

I don't think there's much need for accessing N files concurrently with less than N threads. Probably the best upside for async is an event-driven API like the above to avoid context switching. As with the sockets example, the events should be on big boundaries (entire file?!) and not per byte.

Something to think about -- although Linux specific, io_uring allows for asyncio on both sockets and files with the options to poll instead of making heavy kernel system calls. It's possible to perform I/O using io_uring with very few kernel to user space context switches.

kevincianfarini

comment created time in 7 hours

issue commentsquare/moshi

Expected BEGIN_OBJECT but was BEGIN_ARRAY

@ZacSweers please help!

franquicidad

comment created time in 7 hours

issue commentcashapp/paparazzi

Add support for test filtering to Gradle tasks

Haven't looked at the Gradle plugin implementation, but I wonder if this can be achieved by simply inheriting from the right Gradle task types, smth like Test. Will take a closer look.

Egorand

comment created time in 10 hours

issue openedcashapp/paparazzi

Add support for test filtering to Gradle tasks

As test suites grow, it would be handy to be able to pass filtering arguments to Paparazzi tasks, similar to Gradle's built-in test tasks (see Test filtering):

./gradlew views:recordPaparazziDebug --tests FooView

created time in 10 hours

push eventgoogle/guava

travis-ci

commit sha 15f1e2c51d9d5a2a2902846a68f1a779016b3600

Generate Javadoc and JDiff for Guava HEAD-jre-SNAPSHOT

view details

push time in 11 hours

push eventgoogle/guava

travis-ci

commit sha d2c50349a6535d1dddb7bce5b0cf6edfbacb5d0a

Generate Javadoc and JDiff for Guava HEAD-jre-SNAPSHOT

view details

push time in 11 hours

issue commentsquare/wire

Crash on field tags

I am not able to repro. Is it possible that your proto file is added twice to the whole graph?

If you have a failing test, or a reproducing repo, that'd help.

ToluwaniO

comment created time in 11 hours

issue closedgoogle/guava

AsyncEventBus: Add options to enable ImmediateDispatcher

Since ImmediateDispatcher is depth-first and somehow "preferable", we should offer a choice to use this dispatcher. And for now dispatcher in AsyncEventBus is always coded to legacyDispatcher while constructing(See AsyncEventBus).

closed time in 12 hours

markowitz73

issue commentgoogle/guava

AsyncEventBus: Add options to enable ImmediateDispatcher

Thanks for your feature request. At this point we are not actively developing EventBus. There are several more modern frameworks for event-driven or reactive programming, including RxJava among others.

markowitz73

comment created time in 12 hours

issue closedgoogle/guava

EventBus: Add options to enable ImmediateDispatcher

This ticket is almost the same as #2986 but deals with the EventBus instead of the AsycEventBus object.

I am using the EventBus object not as global object (static or singleton) but on a single instance per user session. In this scenario, instantiating for each EventBus instance an instance of PerThreadQueuedDispatcher with all the ThreadLocal variables does not make much sense. It would be better to have the possibility to use ImmediateDispatcher.INSTANCE by making Dispatcher.immediate() public - as well as changing the package visibility of the class Dispatcher to public. Changing the package visible constructor EventBus(String,Executor,Dispatcher,SubscriberExceptionHandler) would enable much more flexibility.

closed time in 12 hours

ckloner

issue commentgoogle/guava

EventBus: Add options to enable ImmediateDispatcher

Thanks for your feature request. At this point we are not actively developing EventBus. There are several more modern frameworks for event-driven or reactive programming, including RxJava among others.

ckloner

comment created time in 12 hours

delete branch google/guava

delete branch : sync-master-2020/11/30

delete time in 12 hours

push eventgoogle/guava

ghm

commit sha 1a020b7e447bddc48b677d702611f58f7c9033cc

PUBLIC: Add missing Override annotations. RELNOTES=n/a ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=344396802

view details

push time in 12 hours

PR merged google/guava

MOE Sync 2020-11-30 cla: yes internal-sync

This code has been reviewed and submitted internally. Feel free to discuss on the PR, and we can submit follow-up changes as necessary.

Commits:

<p> PUBLIC: Add missing Override annotations.

da5e9d98f43b039c64a62182614f74ca188cd2ce

+7 -10

0 comment

3 changed files

netdpb

pr closed time in 12 hours

push eventsquare/kotlinpoet

Tomasz Krakowiak

commit sha a61e88f6f3e050d601145f88ca149299f1423b14

#1016 Delegated constructor call in external class is not allowed

view details

Tomasz Krakowiak

commit sha 27835f26081b1e6c540d2c612057f86d9e2bddb2

#1018 Expect classes cannot initialize supertypes

view details

Egor Andreevich

commit sha f028a95776d0b58eda5b2492d157b8d39c88a939

Merge pull request #1017 from NiematojakTomasz/issue-1016 #1016 Delegated constructor call in external class is not allowed

view details

push time in 12 hours

issue closedsquare/kotlinpoet

Expect classes cannot initialize supertypes

Sample incorrectly generated code:

public expect open abstract class AbortSignal : EventTarget() {
  public open val aborted: Boolean?
}

Error: "Expected classes cannot initialize supertypes"

closed time in 12 hours

NiematojakTomasz

issue closedsquare/kotlinpoet

Delegated constructor call in external class is not allowed

Sample of invalid generated code:

public open abstract external class AbortSignal : EventTarget() {
  public val aborted: Boolean?
}

closed time in 12 hours

NiematojakTomasz

push eventsquare/okio

swankjesse

commit sha 588ac530bd3bb05cb005ebf2ff16e5ed623e64df

Deploying to gh-pages from @ fcb460efeadf4c1ebc289edc6d47e5c8c841c02a 🚀

view details

push time in 12 hours

push eventsquare/okio

swankjesse

commit sha 7a789b6738531b529c8f1ac1d16c38eda8817346

Deploying to gh-pages from @ fcb460efeadf4c1ebc289edc6d47e5c8c841c02a 🚀

view details

push time in 12 hours

issue commentsquare/okhttp

IllegalArgumentException for the url in the Cache Entry

@dave-r12 I have updated the description with a more detailed and similar configuration. But I also can include it here below.

We can not reproduce the issue, we tried different things but it was impossible so far. After few ideas I could only simulate the behaviour of the issue "corrupting" manually the cache files and that way I was able to get the same stack trace and error, but I couldn't reproduce the root cause and understand why the cache file was corrupted.

We are also happy to provide more detailed information with few production endpoints causing the issue in a private channel if needed.

We are currently using two Okhttp instances configured as follow:

val clientBuilder = OkHttpClient.Builder()

clientBuilder.protocols(listOf(Protocol.HTTP_1_1))

clientBuilder.addInterceptor { chain ->
    val originalRequest = chain.request()
    val requestWithUserAgent = originalRequest.newBuilder()
            .header("User-Agent", "Example/1.0.0 HTTPClient Android").build()
    chain.proceed(requestWithUserAgent)
}

val certificatePinner = CertificatePinner.Builder()
certificatePinner.add("*.example.com", "sha256/public-key-1")
clientBuilder.certificatePinner(certificatePinner.build())

val cacheDir = File(context.cacheDir, "new_caching_directory")
val cache = Cache(cacheDir, (16 * 1024 * 1024).toLong())
clientBuilder.cache(cache)

val okhttpClient = clientBuilder.build()
val loggingInterceptor = HttpLoggingInterceptor()
loggingInterceptor.level = HttpLoggingInterceptor.Level.NONE

val clientBuilder = OkHttpClient.Builder()
        .protocols(listOf(Protocol.HTTP_2, Protocol.HTTP_1_1))
        .addInterceptor(loggingInterceptor)

val certificatePinner = CertificatePinner.Builder()
certificatePinner.add("*.example2.com", "sha256/public-key-2")
clientBuilder.certificatePinner(certificatePinner.build())

val httpClient = clientBuilder.build()
httpClient.dispatcher.maxRequestsPerHost = 32
httpClient.dispatcher.maxRequests = 32

val cacheDir = File(context.cacheDir, "new_caching_directory_2")
val cache = Cache(cacheDir, (8 * 1024 * 1024).toLong())
httpClient.newBuilder().cache(cache).build()
brunoescalona

comment created time in 12 hours

create barnchgoogle/guava

branch : sync-master-2020/11/30

created branch time in 12 hours

PR opened google/guava

MOE Sync 2020-11-30

This code has been reviewed and submitted internally. Feel free to discuss on the PR, and we can submit follow-up changes as necessary.

Commits:

<p> PUBLIC: Add missing Override annotations.

da5e9d98f43b039c64a62182614f74ca188cd2ce

+7 -10

0 comment

3 changed files

pr created time in 12 hours

issue commentsquare/okio

Multiplatform watchOs is missing

Done :)

PaulWoitaschek

comment created time in 12 hours

PR opened square/okio

Added the watchos targets

Fixes #820

+11 -24

0 comment

5 changed files

pr created time in 13 hours

more