Trouble using conversion through JSON
See original GitHub issueHi,
I tried following what you said in the wiki as we have our own implementation of the OpenRTB models:
Note: If adopting openrtb-core’s RTB model classes is difficult for some reason, for example you have legacy code that uses another OpenRTB library, you can just add a step 4 that converts our OpenRtb.BidRequest to a JSON string that can be parsed back to the preferred OpenRTB model. See openrtb-core’s documentation about JSON serialization. For the response just do the reverse, creating the JSON output and parsing that to our OpenRtb.BidResponse that can be mapped to DoubleClick. Notice that these additional JSON serialization steps are very fast (in the order of ~10 microseconds), so don’t worry about extra cost.
My problem is that when I json encode the OpenRtb.BidRequest
(using google GSON) most of the fields are suffixed with an underscore. For instance i have id_
, imp_
, imp_[0].banner_.btype_
.
Our model respects the OpenRTB names (i.e. we have fields named id
, imp
, imp[0].banner.btype
)
Is there anyway to correct this besides doing a complete mapping from one object to the other ?
Thanks
Issue Analytics
- State:
- Created 9 years ago
- Comments:18 (7 by maintainers)
Top GitHub Comments
I see that you’re trying to use GSON (or any automatic JSON mapping API like Jackson’s ObjectMapper) to serialize the content of this library’s types like
OpenRtb.BidRequest
. This will not work well because protoc-generated classes are not proper POJOs; in addition to fields terminated by ‘_’ they have non-JavaBean-standard method names, they have other fields for things like absent/present bits, the UnknownFieldSet, extensions… so you are likely to have other problems in the generated JSON unless you write more workarounds. I just don’t understand why are you trying to do this serialization with GSON, when you could use the includedOpenRtbJson*
API?The booleans converted to
YES
/NO
are easy to explain: first, the OpenRTB specification doesn’t really specify any API, only a JSON format which we do implement strictly (the generated JSON validates correctly with Nexage’s OpenRTB Validator, but let me know if you see any exception). The concrete API that we define with protobuf fills in some gaps or fixes some issues, like the use of 0/1 values for many boolean flags without any good reason (other than the fact that 0/1 use less space in JSON text…). But theOpenRtbJson*
API will correctly serialize these flags as 0/1.Hi,
Here is the working implementation for the latest version (0.8.4).
Mapper:
Registration:
The rest is the same @Crystark exposed.
Best,