Have you solved this?

On Monday, December 17, 2012 at 9:03:50 AM UTC+7, Boris wrote:
>
> On Sun, Dec 16, 2012 at 5:45 PM, Dustin Sallings <dsal...@gmail.com 
> <javascript:>> wrote:
>
>> Boris <boris....@gmail.com <javascript:>> writes:
>>
>> > I have JSON web API that accepts fields URL parameter, like this:
>> >
>> > GET /something/?fields=a,b,c
>> >
>> > This is common pattern in web APIs to send partial objects instead of
>> > full objects. Suppose struct has fields a,b,c,...z, I don't want to
>> > fetch all fields from database, marshall, send, unmarshall, etc. I
>> > know I can add tag to struct fields to suppress them in JSON, but that
>> > is done at compile-time. Is there a way to do this at run-time, or
>> > should I write custom marshaller for this?
>>
>>   You need to implement a custom MarshalJSON for your object that
>> considers some internal fields you configure to specify which parameters
>> are emitted.
>>
>>
> Interesting, so http://golang.org/pkg/encoding/json/#Marshaler is the way 
> to override default marshaling. I guess I will implement some helper 
> function so I don't re-implement this for every single struct type I use, 
> and have an internal field in the item, which I set to indicate which 
> fields to include. If anyone has anything else to add, like an example 
> implementation or tips for efficiency, I will appreciate.
>
> Thanks
> Boris
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/09b0a4c5-92a6-4948-aae9-77cc713d4438%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to