actgardner / gogen-avro

Generate Go code to serialize and deserialize Avro schemas
MIT License
366 stars 87 forks source link

Autogenerated MarshalJSON function does not respect ordering #193

Open galion96 opened 2 years ago

galion96 commented 2 years ago

Hello,

I am using this library as a validator before streaming data to PubSub, and since avro requires a strict order I assumed that MarshalJSON is ment to respect that ordering, and the method does seem to do some only to call json.Marhsal in the end and ruin the order. Is this intended? Code example that was autogenerated from avro schema-

function(r SomeStruct) MarshalJSON() ([]byte, error) {
    var err error
    output := make(map[string]json.RawMessage)
    output["filedA"], err = json.Marshal(r.fieldA)
    if err != nil {
        return nil, err
    }
    output["fieldB"], err = json.Marshal(r.fieldB)
    if err != nil {
        return nil, err
    }
    output["fieldC"], err = json.Marshal(r.fieldC)
    if err != nil {
        return nil, err
    }
    output["fieldD"], err = json.Marshal(r.fieldD)
    if err != nil {
        return nil, err
    }
    output["fieldE"], err = json.Marshal(r.fieldE)
    if err != nil {
        return nil, err
    }
    return json.Marshal(output)

Is this intended?