Skip to content

Adding support to encoding of nested struct arrays #8

Open

Description

@etxnija

I plan to fix the issue described below for encoding nested struct arrays.

Currently this structure

type Nested struct {
    A string `url:"theA,omitempty"`
    B string `url:"theB,omitempty"`
}
type NestedArr []Nested
na := struct {
        A NestedArr `url:"arr"`
        B Nested    `url:"nested"`
    }{
        A: NestedArr{Nested{
            A: "aa",
            B: "bb",
        }, Nested{
            A: "aaa",
            B: "bbb"}},
        B: Nested{
            A: "zz",
            B: "xx",
        },
    }

encode to

arr={aa bb}&arr={aaa bbb}&nested[theA]=zz&nested[theB]=xx

To be consistent with the Ruby style parsing the result should look like this

 arr[0][theA]=aa&arr[0][theB]=bb&arr[1][theA]=aaa&arr[1][theB]=bbb&nested[theA]=zz&nested[theB]=xx

Activity

  1. tamalsaha commented on May 4, 2017

    @tamalsaha

    @etxnija , this is a very old bug. We needed similar ruby like encoding. We have addressed this in our fork https://github.com/appscode/go-querystring .

  2. willnorris commented on Feb 24, 2021

    @willnorris
    Collaborator

    I'll leave this issue open for anyone that still needs this and wants to implement.

    Looks like @tamalsaha's initial implementation was pretty simple: appscode#2

  3. kokizzu commented on Jun 9, 2022

    @kokizzu

    @tamalsaha that one also give wrong for []string it gives something like this a%5B0%5D=1 instead of a[]=1

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions