Skip to content

Conversation

@joshfriend
Copy link

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Describe the solution you've provided

I Added Serializable to any base classes and interfaces needed to make LDContext itself serializable

Describe alternatives you've considered

My workaround for this was to manually serialize the LDContext to json because string is serializable and deserialize it again

Additional context

I was trying to use launchdarkly sdks inside of some gradle tooling that configures build features based on feature flags. To do this I wrote a ValueSource which took the following parameters:

  • Feature flag key
  • SDK key
  • LDContext

And gradle threw an error because LDContext is not serializable, and therefore not allowed as a ValueSourceParameters property.

I'm hoping that code will be open source soon, but for now here's a snippet:

abstract class LDBooleanValueSource: ValueSource<Boolean, LDBooleanValueSource.Params> {
  interface Params : ValueSourceParameters {
    val flagName: Property<String>
    val sdkKey: Property<String>
    val context: Property<LDContext> // Not serializable!
  }

  companion object {
    private val config: LDConfig = LDConfig.Builder().build()

    @JvmStatic
    fun ProviderFactory.launchDarklyBoolean(flagName: String, context: LDContext): Provider<Boolean> {
      return of(LDBooleanValueSource::class.java) {
        it.parameters.flagName.set(flagName)
        it.parameters.sdkKey.set(gradleProperty("launchdarkly.sdkKey"))
        it.parameters.context.set(context)
      }
    }
  }

  private val client by lazy { LDClient(parameters.sdkKey.get(), config) }

  override fun obtain(): Boolean =
    client.allFlagsState(parameters.context.get())
      .getFlagValue(parameters.flagName.get())
      .booleanValue()
}

@joshfriend joshfriend requested a review from a team as a code owner January 8, 2026 02:36
@joshfriend joshfriend force-pushed the ldcontext-serializable branch from fa5cb4a to f198141 Compare January 8, 2026 13:36
@joshfriend joshfriend changed the title JsonSerializable extends java.io.Serializable feat: LDContext is java.io.Serializable Jan 8, 2026
@tanderson-ld
Copy link
Contributor

Hi @joshfriend and thank you for the contribution. I will try to take a look in the next day or two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants