Uploaded image for project: 'Couchbase .NET client library'
  1. Couchbase .NET client library
  2. NCBC-2706

Unexpected character encountered while parsing value

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Not a Bug
    • 3.0.7
    • 3.1.0
    • library
    • None
    • 1

    Attachments

      No reviews matched the request. Check your Options in the drop-down menu of this sections header.

      Activity

        jmorris Jeff Morris added a comment - - edited

        After consideration, this is not a bug but expected behavior. If you write a document to the database using a POCO, the JSON format looks like this:

        {"foo":"foo","bar":10}
        

        Note there are no leading or trailing quotations. If you try to read and treat it as a string, you'll get the "Unexpected character encountered while parsing value" error as its not a well-formed string; the JSON parser expects:

        "{\"foo\":\"foo\",\"bar\":10}"
        

        If you expect to deserialize it to a string; the format is wrong. Now, if you write it as a string to the database, the JsonTranscoder will correctly add the quotations:

        "{\"foo\":\"foo\",\"bar\":10}"
        

        If you have done this, then the JSON parser will recieve:

        "{\"foo\":\"foo\",\"bar\":10}"
        

        As expected and the deserialization will succeed.

        NOTE: for certain situations you may need to swap out the ITranscoder type to LegacyTranscoder, RawStringTranscoder, etc. to explicitly specify there meaning.

        jmorris Jeff Morris added a comment - - edited After consideration, this is not a bug but expected behavior. If you write a document to the database using a POCO, the JSON format looks like this: {"foo":"foo","bar":10} Note there are no leading or trailing quotations. If you try to read and treat it as a string, you'll get the "Unexpected character encountered while parsing value" error as its not a well-formed string; the JSON parser expects: "{\"foo\":\"foo\",\"bar\":10}" If you expect to deserialize it to a string; the format is wrong. Now, if you write it as a string to the database, the JsonTranscoder will correctly add the quotations: "{\"foo\":\"foo\",\"bar\":10}" If you have done this, then the JSON parser will recieve: "{\"foo\":\"foo\",\"bar\":10}" As expected and the deserialization will succeed. NOTE: for certain situations you may need to swap out the ITranscoder type to LegacyTranscoder, RawStringTranscoder, etc. to explicitly specify there meaning.

        People

          jmorris Jeff Morris
          jmorris Jeff Morris
          Votes:
          0 Vote for this issue
          Watchers:
          1 Start watching this issue

          Dates

            Created:
            Updated:
            Resolved:

            Gerrit Reviews

              There are no open Gerrit changes

              PagerDuty