I need to export some large structs via JSON, and take back JSON strings for updating only some of it's attributes.
Let's have following struct:
type House struct {
Name string `json:"name"`
Rooms int `json:"rooms_count"`
Owner *Owner `json:"-"`
}
Encoding that with encoding/json
will result in a JSON string like
{"name":"some name", "rooms_count":5}
I now get this JSON string:
{"name":"some other name", "rooms_count":7, Owner:{something...}}
The user wants to change every attribute. Owner
is not allowed, because it's not exported. But I only want to only permit changes of rooms_count
. Is there any way of saying that some attributes should be exported with the Encoder
, but not be used by the Decoder
? Having to write all these checks manualy would be very unpleasant.