Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

GrowthBook v2 Json Arrays Deserialized as "Unknown" #169

Open
sbelloz opened this issue Feb 4, 2025 · 5 comments
Open

GrowthBook v2 Json Arrays Deserialized as "Unknown" #169

sbelloz opened this issue Feb 4, 2025 · 5 comments

Comments

@sbelloz
Copy link

sbelloz commented Feb 4, 2025

Hi!

We noticed that the latest major v2 update of GrowthBook does not properly handle arrays.
When it encounters an array node, it deserializes it as Unknown.
Additionally, I want to ask you how can I obtain a json String or a Map<String, JsonElement> from a GbJson? Maybe having extensions that allow deserialization exclusively on the client side could be useful.

@sbelloz sbelloz changed the title GrowthBook v2 Json Arrays Deserialized as 'Unknown' GrowthBook v2 Json Arrays Deserialized as "Unknown" Feb 4, 2025
@Bohdan-Kim
Copy link
Collaborator

Hello!

No such an option as array for feature value type, but array is used in "in list of values" rule. Seems like you are using this rule

Image

@Bohdan-Kim
Copy link
Collaborator

Support for arrays is added in this request (it is not approved yet)

@Bohdan-Kim
Copy link
Collaborator

If it is crucial you need to use v1.1.64

@Bohdan-Kim
Copy link
Collaborator

For having extensions that allow deserialization exclusively on the client side we should create separate artifact growthbook-kotlinx-serialization as we can't force to use kotlinx-serialization (someone can use Gson)

For fix it right here right now you need to copy this to your project:

fun GBValue.gbSerialize(): JsonElement =
        when(this) {
            is GBBoolean -> JsonPrimitive(this.value)
            is GBString -> JsonPrimitive(this.value)
            is GBNumber -> JsonPrimitive(this.value)
            is GBArray -> JsonArray(
                this.map { it.gbSerialize() }
            )
            is GBJson -> JsonObject(
                this.mapValues { it.value.gbSerialize() }
            )
            is Unknown -> JsonNull
        }

@Bohdan-Kim
Copy link
Collaborator

This issue is fixed in v3.0.0-alpha

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants