question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

problem parsing json for request that contain 'native' key

See original GitHub issue

Hi,

While trying to add support for open RTB 2.3 I would like to support native adds, I took an example of native ad request from the specification document:

{  
   "id":"80ce30c53c16e6ede735f123ef6e32361bfc7b22",
   "at":1,
   "cur":[  
      "USD"
   ],
   "imp":[  
      {  
         "id":"1",
         "bidfloor":0.03,
         "native":{  
            "request":"...Native Spec request as an encoded string...",
            "ver":"1.0",
            "api":[  
               3
            ],
            "battr":[  
               13,
               14
            ]
         }
      }
   ],
   "site":{  
      "id":"102855"      "cat":[  
         "IAB3-1"
      ],
      "domain":"www.foobar.com",
      "page":"http://www.foobar.com/1234.html ",
      "publisher":{  
         "id":"8953",
         "name":"foobar.com",
         "cat":[  
            "IAB3-1"
         ],
         "domain":"foobar.com"
      }
   },
   "device":{  
      "ua":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13 
(KHTML, like Gecko) Version/5.1.7 Safari/534.57.2",
      "ip":"123.145.167.10"
   },
   "user":{  
      "id":"55816b39711f9b5acf3b90e313ed29e51665623f"
   }

Reading the message model in openrtb.proto I noticed:

message Native {
      oneof request_oneof {
        // Request payload complying with the Native Ad Specification.
        // Exactly one of {request, request_native} should be used;
        // this is the OpenRTB-compliant field for JSON serialization.
        // [AdX: BidRequest.AdSlot.NativeAdTemplate]
        string request = 1;

        // Request payload complying with the Native Ad Specification.
        // Exactly one of {request, request_native} should be used;
        // this is an alternate field preferred for Protobuf serialization.
        // [AdX: BidRequest.AdSlot.NativeAdTemplate]
        NativeRequest request_native = 50;
      }
      ...
}

I understand that the native object should contain either a string with the field request or the object NativeRequest

But when I run the request I get the error:

com.fasterxml.jackson.core.JsonParseException: Unexpected character (‘.’ (code 46)): expected a valid value (number, String, array, object, ‘true’, ‘false’ or ‘null’) at [Source: java.io.CharArrayReader@3a9fcbdf; line: 1, column: 2]

From debugging the code I saw the following: In class OpenRtbJsonReader::protected void readNativeField(JsonParser par, Native.Builder nativ, String fieldName) there is a switch case and for the possible fields and there is only request which is set as NativeRequest and not as a string as mentioned in the proto (also, the object itself which is generated by protobuf has a string field for request and a NativeRequest objects from request_native. Therefore the string

…Native Spec request as an encoded string…

which is set in the request can’t be set to the OpenRTB.BidRequest object.

Can you please help me what I am doing wrong? or maybe there is some bug? I can’t get it working with a native request to my server.

Thank you.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
bundeskanzler4711commented, Jun 2, 2016

Hi @elic9,

In OpenRTB Native 1.0 the imp.native field is included as a JSON-encoded string in the bid request. It’s the same for the native creative; it is returned as a JSON-encoded string in the adm field of the bid response. While Native 1.0 supported only an encoded string, the current draft for 1.1 adds support for a direct object and encourages adoption of that option to reduce confusion. Please have a look at http://www.iab.com/wp-content/uploads/2016/01/OpenRTB-Native-Ads-Specification-Draft.pdf chapter 4.1 and 5 for more information.

Like you I’m not really happy with it. Please have a look at my pull request https://github.com/google/openrtb/pull/87 in which I try to fix/improve the behavior and prepare OpenRTB Native 1.1 compatibility.

1reaction
avitalelicommented, Jun 2, 2016
Read more comments on GitHub >

github_iconTop Results From Across the Web

What Is JSON and How to Handle an “Unexpected Token” Error
Learn what JSON is and how you can deal with errors occurring when parsing JSON data, such as "Unexpected Token < in JSON...
Read more >
SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
JSON.parse() parses a string as JSON. This string has to be valid JSON and will throw this error if incorrect syntax was encountered....
Read more >
JSON Parse error: Unrecognized token'<' - react-native
This Means you are getting Html response from the server probably a 404 or 500 error. Instead of response.json() use response.text() you ...
Read more >
Python Parse JSON response using requests library - PYnative
Learn how to parse JSON response using the requests library. Access data from JSON response ... Access Nested JSON key directly from response....
Read more >
How to parse JSON in SQL Server
JSON has a compact data structure and it does not include unnecessary data notations; JSON has extensive usage. All modern programming languages ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found