google / openrtb

OpenRTB model for Java and other languages via protobuf; Helper OpenRTB libraries for Java including JSON serialization
Apache License 2.0
398 stars 190 forks source link

Extension Json Serialization Documentation Lacking #107

Closed YoavNordmann closed 7 years ago

YoavNordmann commented 7 years ago

Hi

I am desperately trying to configure the JSON Serialization/deserialization for an extension I wrote such as this:

`message BidResponseErrors {

extend com.google.openrtb.BidResponse{
    repeated string errors = 100;   
}

extensions 100 to 9999;

}`

I am able to Add data to the extension and I can see it using the debugger. But I cannot figure out how to write the BidResponseErrorsWriter and the BidResponseErrorsReader, how to initialize them and what to write inside.

I am lacking a lot of documentation. So far this is what I have:

The writer: public class BidResponseErrorsWriter extends OpenRtbJsonExtWriter<BidResponseErrors> { @Override protected void write(BidResponseErrors value, JsonGenerator gen) throws IOException { gen.writeStartArray(); gen.writeEndArray(); } } The Reader: public class BidResponseErrorsReader extends OpenRtbJsonExtReader<BidResponseErrors.Builder>{ protected void read(Builder msg, JsonParser par) throws IOException { } }

And the registration: OpenRtbJsonWriter jsonWriter = OpenRtbJsonFactory.create() .register(new BidResponseErrorsWriter(), BidResponseErrors.class, BidResponse.class) .newWriter();

Needless to say that nothing here works, and the writer method is not invoked. Any help would be very much appreciated.

Thank You

Yoav

YoavNordmann commented 7 years ago

Hi I see a lot of documentation on how to add an extension using the proto files and then adding and using that extension. I see no documentation which has an example including json serialization. If you would help me I would be happy to write a blog explaining said example from beginning to end. Yoav

opinali commented 7 years ago

Did you try checking the included unit tests here? These tests are reasonably documented so that can also be useful as samples; you will find one for each possible scenario. I know it's not as good as a detailed tutorial document but maybe this can clarify things.