Is it me, or is the JSON format knocking this out?

64 views
Skip to first unread message

Adrian Inman

unread,
Jul 2, 2012, 5:00:43 PM7/2/12
to rest...@googlegroups.com
I am trying to work with the Shopify API. A sample piece of JSON is shown at the bottom

I have a POCO which looks like this:

public class Product
    {
        public int id { get; set; }
        public string Title { get; set; }
        //public string BodyHtml { get; set; }
        public string Handle { get; set; }
    }

    public class Products : List<Product> { }

When I call 

IRestResponse<Products> productsResponse = client.Execute<Products>(request);

I get an exception as BuildList in JsonDeserializer gets upset on line 201 as it is coded to look for the [0] item in the array returned from type.GetGenericArguments() which actually returns a zero length array and so everything falls over.

HELP! I'd dearly love some specific / up to date examples. I'm sure RestSharp is what I need, but not sure what I'm missing.

Thanks in advance.


{
  • products:
    [
    • {
      • body_html: "<p>WatchGuard XTM 22 1 year Security Software Suite</p> ",
      • created_at: "2012-05-31T23:33:56+01:00",
      • handle: "watchguard-xtm-22-1-year-security-software-suite-wg017714-wg017714",
      • id: 93303544,
      • product_type: "Firewall Security Licence",
      • published_at: "2012-05-31T23:33:56+01:00",
      • template_suffix: null,
      • title: "WatchGuard XTM 22 1 year Security Software Suite (WG017714)",
      • updated_at: "2012-06-24T18:18:04+01:00",
      • vendor: "WatchGuard",
      • tags: "",
      • variants:
        [
        • {
          • compare_at_price: null,
          • created_at: "2012-05-31T23:33:56+01:00",
          • fulfillment_service: "manual",
          • grams: 0,
          • id: 218267520,
          • inventory_management: null,
          • inventory_policy: "deny",
          • option1: "Default Title",
          • option2: null,
          • option3: null,
          • position: 1,
          • price: "219.93",
          • product_id: 93303544,
          • requires_shipping: false,
          • sku: "WG017714",
          • taxable: true,
          • title: "Default Title",
          • updated_at: "2012-06-01T21:15:01+01:00",
          • inventory_quantity: 1
          }
        ],
      • images:
        [],
      • options:
        [
        • {
          • name: "Title"
          }
        ]
      }
    • }

Peter Johanson

unread,
Jul 2, 2012, 5:12:37 PM7/2/12
to rest...@googlegroups.com
Adrian,

There's a pull request to address this issue:
https://github.com/restsharp/RestSharp/pull/236

Unfortunately, it was written right before the move from Json.Net to
SimpleJson. If you want to create a pull request that implements the
logic from that one, but for the new deserializer approach, I will be
happy to merge it in before we do the next release.

-pete

On Mon, Jul 02, 2012 at 02:00:43PM -0700, Adrian Inman wrote:
> I am trying to work with the Shopify API. A sample piece of JSON is
> shown at the bottom
>
> I have a POCO which looks like this:
>
> public class Product
> {
> public int id { get; set; }
> public string Title { get; set; }
> //public string BodyHtml { get; set; }
> public string Handle { get; set; }
> }
> public class Products : List<Product> { }
> When I call
> IRestResponse<Products> productsResponse =
> client.Execute<Products>(request);
> I get an exception as BuildList in JsonDeserializer gets upset on line
> 201 as it is coded to look for the [0] item in the array returned
> from type.GetGenericArguments() which actually returns a zero length
> array and so everything falls over.
> HELP! I'd dearly love some specific / up to date examples. I'm sure
> RestSharp is what I need, but not sure what I'm missing.
> Thanks in advance.
> {
> * products:
> [
> + {
> o body_html: "<p>WatchGuard XTM 22 1 year Security Software
> Suite</p> ",
> o created_at: "2012-05-31T23:33:56+01:00",
> o handle:
> "watchguard-xtm-22-1-year-security-software-suite-wg01771
> 4-wg017714",
> o id: 93303544,
> o product_type: "Firewall Security Licence",
> o published_at: "2012-05-31T23:33:56+01:00",
> o template_suffix: null,
> o title: "WatchGuard XTM 22 1 year Security Software Suite
> (WG017714)",
> o updated_at: "2012-06-24T18:18:04+01:00",
> o vendor: "WatchGuard",
> o tags: "",
> o variants:
> [
> # {
> @ compare_at_price: null,
> @ created_at: "2012-05-31T23:33:56+01:00",
> @ fulfillment_service: "manual",
> @ grams: 0,
> @ id: 218267520,
> @ inventory_management: null,
> @ inventory_policy: "deny",
> @ option1: "Default Title",
> @ option2: null,
> @ option3: null,
> @ position: 1,
> @ price: "219.93",
> @ product_id: 93303544,
> @ requires_shipping: false,
> @ sku: "WG017714",
> @ taxable: true,
> @ title: "Default Title",
> @ updated_at: "2012-06-01T21:15:01+01:00",
> @ inventory_quantity: 1
> }
> ],
> o images:
> [
> # {
> @ created_at: "2012-06-24T18:18:05+01:00",
> @ id: 189312170,
> @ position: 1,
> @ product_id: 93303544,
> @ updated_at: "2012-06-24T18:18:05+01:00",
> @ src:
> "[1]http://cdn.shopify.com/s/files/1/0158/8830/
> products/watchguard_9260289.png?704"
> }
> ],
> o options:
> [
> # {
> @ name: "Title"
> }
> ]
> }
> + }
>
> References
>
> 1. http://cdn.shopify.com/s/files/1/0158/8830/products/watchguard_9260289.png?704

--

Adrian Inman

unread,
Jul 3, 2012, 5:27:21 PM7/3/12
to rest...@googlegroups.com
Thanks. I'd love to, but not sure I would be able to do it reliably for integration.
I have found a workaround which is confusing me though - call like this:

client.Execute<List<Product>>(request) seems to work fine. I just have to specify the name of the RootElement which isn't too hard to do and away it goes.

Cristovão Morgado

unread,
Jul 3, 2012, 6:15:53 PM7/3/12
to rest...@googlegroups.com
Try using 
http://json2csharp.com/
--
Cristovao Morgado
@TheSaintr


Reply all
Reply to author
Forward
0 new messages