I have a struct like this -
type Address struct {
AddressLine1 string `json:"addressLine1" bson:"addressLine1"`
AddressLine2 string `json:"addressLine2" bson:"addressLine2"`
Landmark string `json:"landmark" bson:"landmark"`
Zipcode string `json:"zipcode" bson:"zipcode"`
City string `json:"city" bson:"city"`
}
Due to some compatibility issues between the previous build and the latest yet-to-be-released build, I want to make sure that if someone posts json data that decodes using this struct they should be able to use either 'zipcode' or 'pincode' as the field name in their json. But when this value is written to my database, the field name should only be 'zipcode'.
In short,
{
"city": "Mumbai",
"zipcode": "400001"
}
or
{
"city": "Mumbai",
"pincode": "400001"
}
should both appear inside the database as -
{
"city": "Mumbai",
"zipcode": "400001"
}
How do I allow this?