QUSIR / staff

Automatically exported from code.google.com/p/staff
Apache License 2.0
0 stars 0 forks source link

array in struct return missing value in json format #214

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

I wrote those code like these :-
Complex.h
....
struct Basic
{
    float a;
    float b;
    float c;
};

struct Cmplex
{
    double t1;
    double t2;
    double t3;
    double t4;
    Basic x;
    Basic y;
    Basic z;
    int b[5];
};
...
    virtual Cmplex Show(int a, int b, int c, int d) = 0;

in ComplexImpl.cpp 
...
Cmplex ComplexImpl::Show(int a, int b, int c, int d)
{
  Cmplex tResult;
  tResult.t1 = 22/7;
  tResult.t2 = 22.0/7.0;
  tResult.t3 = 22/7.0;
  tResult.t4 = 22.0/7;
  tResult.x.a = a;
  tResult.x.b = b;
  tResult.x.c = c;
  tResult.y.a = a*d;
  tResult.y.b = b*d;
  tResult.y.c = c*d;
  tResult.z.a = a*a;
  tResult.z.b = b*b;
  tResult.z.c = c*c;
  tResult.b[0] = 9;
  tResult.b[1] = 8;
  tResult.b[2] = 7;
  tResult.b[3] = 6;
  tResult.b[4] = 5;

  return tResult;  // result
}
....

and I get these following in result

JSON Result: 
{"ShowResult":{"t1":"3.000000","t2":"3.142857","t3":"3.142857","t4":"3.142857","
x":{"a":"15.000000","b":"25.000000","c":"11.000000"},"y":{"a":"120.000000","b":"
200.000000","c":"88.000000"},"z":{"a":"225.000000","b":"625.000000","c":"121.000
000"},"b[5]":"-1234027816"}}

at the end of line you will see "b[5]":"-1234027816" which is value of

  tResult.b[0] = 9;
  tResult.b[1] = 8;
  tResult.b[2] = 7;
  tResult.b[3] = 6;
  tResult.b[4] = 5;

What is the expected output? What do you see instead?

I would like to see "b":[9,8,7,6,5]

What version of the product are you using? On what operating system?

Ubuntu 12.04 LTS

Please provide any additional information below.

Original issue reported on code.google.com by vacharap...@gmail.com on 17 Aug 2013 at 9:53

GoogleCodeExporter commented 9 years ago
Unfortunately Staff does not support C style arrays.

To work with arrays you must use std::list or std::vector container.

struct Data
{
  int id;
  std::string str;
  std::list<int> intList;
}

Original comment by loentar on 18 Aug 2013 at 6:06

GoogleCodeExporter commented 9 years ago
Many Thanks Loentar :)

Original comment by vacharap...@gmail.com on 18 Aug 2013 at 7:51