Giter Club home page Giter Club logo

esj's People

Contributors

btcinsight avatar g40 avatar tustvold avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

esj's Issues

Windows stringer.h error while compiling

Hi there,
First of all I want to thank you for this library it's really easy to use and incorporate into C++ projects. I've already tested it in Linux and OSx and it works as described. However in windows I found that when adding the library in a visual studio project (adding the downloaded project folder to the include directories) at compiling time it shows C2589 Errors (12) and C4003 Warnings (6) at lines:

			T imin = std::numeric_limits<T>::min();
			T imax = std::numeric_limits<T>::max();

from DoubleConverter::Convert, part of stringer.h

As usual googling the problem I found the following StackOverflow solution warning C4003 and errors C2589 and C2059 on: x = std::numeric_limits::max()

I opted to include this as a workaround:

#ifdef _MSC_VER
			T imin = (std::numeric_limits<T>::min)();
			T imax = (std::numeric_limits<T>::max)();
#else
			T imin = std::numeric_limits<T>::min();
			T imax = std::numeric_limits<T>::max();
#endif

I know this might not be the most optimal solution, so I thought that creating an issue would be the best thing to do in order to get your feedback and considerations.

Thanks for your time.

Overloading issue in stringer.h

Hi there,

I'm trying to compile on OS X using XCode and am getting the following error.

Thanks.

g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin18.2.0
In file included from ./json_lexer.h:67:
./stringer.h:590:21: error: call to 'toString' is ambiguous
        m_buffer += toString(arg,10);
                    ^~~~~~~~
./stringer.h:100:21: note: candidate function
        inline std::string toString(int64_t value, int base = 10, unsigned int padding = 0)
                           ^
./stringer.h:143:21: note: candidate function
        inline std::string toString(int value, int base = 10)
                           ^
./stringer.h:149:21: note: candidate function
        inline std::string toString(unsigned int value, int base = 10)
                           ^
1 error generated.

thread-safe

Can you make a statement about ESJ's thread safety? I am interested in using it in a multi threaded application.

Thanks!

Serialization of nested classes produces faulty JSON

If we serialize nested classes (depth of 2 or more), it produces faulty JSON code (a closing '}' is missing)

The code below shows the bug. It produces the following JSON:
{"A":{"a":[{"B":{"b":[]}]}}
instead of:
{"A":{"a":[{"B":{"b":[]}}]}}
The '}' closing the B object is missing.

Code sample producing the error:

class C{
public:
    string c;

    void serialize(JSON::Adapter& adapter){
        JSON::Class root(adapter, "C");
        JSON_T(adapter, c);
    }
};

class B{
public:
    vector<C> b;

    void serialize(JSON::Adapter& adapter){
        JSON::Class root(adapter, "B");
        JSON_T(adapter, b);
    }
};

class A{
public:
    vector<B> a;

    void serialize(JSON::Adapter& adapter){
        JSON::Class root(adapter, "A");
        JSON_T(adapter, a);
    }
};

int main(int argc, char** argv) {

    A a;
    a.a.push_back(B());
    cout << JSON::producer<A>::convert(a) << endl;

    return 0;
}

<vector> in json_adapter.h

Had to add #include < vector >
json_adapter.h(312): error C2039: 'vector': is not a member of 'std'

VS2017....

thanks!

'int64_t' and 'long' type ambiguity on 'arm64v8'

First of all, excellent project!

When building for Android using NDK, the architecture arm64v8, both gnu and clang toolchains have a problem with overloading in stringer.h:

inline std::string toString(long value, int base = 10)

and

inline std::string toString(int64_t value, int base = 10)
clang: Error:(143, 24) redefinition of 'std::__1::string Chordia::toString(long int, int)'
gnu: Error:(143, 24) redefinition of 'std::string Chordia::toString(long int, int)'

What worked for me:

#if LONG_MAX != LLONG_MAX
    inline std::string toString(long value, int base = 10)
    {
        return toString((int64_t)value,base);
    }
#endif

I'm using C++11 but trying to apply std::enable_if, which also normally works, brought me headache on Android.

Not able to build source code on linux

I am not able to build this source code on linux with gcc 4.3.
it gives me error as shown below:

./Stringifier/stringer.h:324: error: call of overloaded ‘abs(int64_t&)’ is ambiguous
/usr/include/c++/4.4/cmath:94: note: candidates are: double std::abs(double)
/usr/include/c++/4.4/cmath:98: note: float std::abs(float)
/usr/include/c++/4.4/cmath:102: note: long double std::abs(long double)
In file included from ../Stringifier/json_adapter.h:66,
from ../Stringifier/json_writer.h:59,
from ../Stringify.h:17,
from ../TestBBS.cpp:3:
../Stringifier/json_lexer.h: In function ‘void JSON::throw_if(JSON::ISource*, bool, std::string)’:
../Stringifier/json_lexer.h:227: error: expected primary-expression before ‘)’ token
../Stringifier/json_lexer.h: In function ‘void JSON::throw_if(bool, Chordia::stringer&)’:
../Stringifier/json_lexer.h:237: error: expected primary-expression before ‘)’ token
In file included from ../Stringifier/json_writer.h:59,
from ../Stringify.h:17,
from ../TestBBS.cpp:3:
../Stringifier/json_adapter.h: At global scope:
../Stringifier/json_adapter.h:260: error: ‘std::vector’ has not been declared
../Stringifier/json_adapter.h:260: error: expected ‘,’ or ‘...’ before ‘<’ token
../Stringifier/json_adapter.h: In function ‘void JSON::stream(JSON::Adapter&, const std::string&, int)’:
../Stringifier/json_adapter.h:269: error: ‘is_same’ is not a member of ‘std’
../Stringifier/json_adapter.h:269: error: expected primary-expression before ‘,’ token
../Stringifier/json_adapter.h:269: error: expected primary-expression before ‘>’ token
../Stringifier/json_adapter.h:269: error: ‘::value’ has not been declared
../Stringifier/json_adapter.h:270: error: ‘is_same’ is not a member of ‘std’
../Stringifier/json_adapter.h:270: error: expected primary-expression before ‘,’ token
../Stringifier/json_adapter.h:270: error: expected primary-expression before ‘>’ token
../Stringifier/json_adapter.h:270: error: ‘::value’ has not been declared
../Stringifier/json_adapter.h:271: error: ‘is_integral’ is not a member of ‘std’
../Stringifier/json_adapter.h:271: error: expected primary-expression before ‘>’ token
../Stringifier/json_adapter.h:271: error: ‘::value’ has not been declared
../Stringifier/json_adapter.h:272: error: ‘is_floating_point’ is not a member of ‘std’
../Stringifier/json_adapter.h:272: error: expected primary-expression before ‘>’ token
../Stringifier/json_adapter.h:272: error: ‘::value’ has not been declared
../Stringifier/json_adapter.h:276: error: ‘stream_primitives’ was not declared in this scope
../Stringifier/json_adapter.h:276: error: expected primary-expression before ‘>’ token
../Stringifier/json_adapter.h:276: error: ‘value’ was not declared in this scope
../Stringifier/json_adapter.h:276: error: ‘more’ was not declared in this scope
../Stringifier/json_adapter.h:280: error: ‘stream_classes’ was not declared in this scope
../Stringifier/json_adapter.h:280: error: expected primary-expression before ‘>’ token
../Stringifier/json_adapter.h:280: error: ‘value’ was not declared in this scope
../Stringifier/json_adapter.h:280: error: ‘more’ was not declared in this scope
../Stringifier/json_adapter.h: At global scope:
../Stringifier/json_adapter.h:294: error: ‘std::vector’ has not been declared
../Stringifier/json_adapter.h:294: error: expected ‘,’ or ‘...’ before ‘<’ token
../Stringifier/json_adapter.h: In function ‘void JSON::stream_primitives(JSON::Adapter&, const std::string&, int)’:
../Stringifier/json_adapter.h:296: error: ‘vector’ in namespace ‘std’ does not name a type
../Stringifier/json_adapter.h:296: error: expected unqualified-id before ‘<’ token
../Stringifier/json_adapter.h:302: error: ‘iterator_t’ was not declared in this scope
../Stringifier/json_adapter.h:302: error: expected ‘;’ before ‘it’
../Stringifier/json_adapter.h:303: error: ‘it’ was not declared in this scope
../Stringifier/json_adapter.h:303: error: ‘value’ was not declared in this scope
../Stringifier/json_adapter.h:316: error: ‘more’ was not declared in this scope
../Stringifier/json_adapter.h:344: error: ‘value’ was not declared in this scope
../Stringifier/json_adapter.h:349: error: ‘more’ was not declared in this scope
../Stringifier/json_adapter.h: At global scope:
../Stringifier/json_adapter.h:360: error: ‘std::vector’ has not been declared
../Stringifier/json_adapter.h:360: error: expected ‘,’ or ‘...’ before ‘<’ token
../Stringifier/json_adapter.h: In function ‘void JSON::stream_classes(JSON::Adapter&, const std::string&, int)’:
../Stringifier/json_adapter.h:362: error: ‘vector’ in namespace ‘std’ does not name a type
../Stringifier/json_adapter.h:362: error: expected unqualified-id before ‘<’ token
../Stringifier/json_adapter.h:368: error: ‘iterator_t’ was not declared in this scope
../Stringifier/json_adapter.h:368: error: expected ‘;’ before ‘it’
../Stringifier/json_adapter.h:369: error: ‘it’ was not declared in this scope
../Stringifier/json_adapter.h:369: error: ‘value’ was not declared in this scope
../Stringifier/json_adapter.h:386: error: ‘more’ was not declared in this scope
../Stringifier/json_adapter.h:417: error: ‘value’ was not declared in this scope
../Stringifier/json_adapter.h:422: error: ‘more’ was not declared in this scope

Failed unit tests for DoubleConverter

Running unit tests shows both test_converter and test_conversion failing.

After investigating I noticed that DoubleConverter::Convert runs Chordia::toString(iv, digits) to convert the fractional part of the number (int64_t iv) to a string. However the function it calls is toString(int64_t value, int base = 10) when clearly the function that was meant to be called is toString(double value,double precision = 0.0001).
This results in the fractional part of the number being represented in binary and causing the unit tests to fail.

This issue was introduced recently by 301e17e

Unnamed objects support

Hi!
Your example

class JSONExample
{
public:
    std::string text;
...
}

Serializes into {"JSONExample":{"text":"Hello JSON World"}}. Is it possible to serialize them into just
{"text":"Hello JSON World"} ? Suppose I need to serialize a vector of JSONExample instances, so after serialization I'd like to have:
[{"text":"Hello JSON World 1"}, {"text":"Hello JSON World 2"}]

Vector of types with inner types

Serializing a vector of types with inner types produces incorrect JSON:

The following code, for example :


class F {
public:
    F() : element(4) {
        
    }
    
    void serialize(JSON::Adapter& adapter) {
        JSON::Class root(adapter,"F");
        JSON_T(adapter, element);
    }
protected:
    int element;
};

class E {
public:
    
    
    E() : element1(54) {
        
    }
    
    void serialize(JSON::Adapter& adapter) {
        JSON::Class root(adapter,"E");
        JSON_E(adapter, element1);
        JSON_T(adapter, element2);
    }
protected:
    int element1;
    F element2;
};

class D {
public:
    
    void serialize(JSON::Adapter& adapter) {
        JSON::Class root(adapter,"D");
        JSON_T(adapter, data);
    }
    
    std::vector data;
};

Produces

{"D":{"data":[{"E":{"element1":54,{"F":{"element":4}}}}]}}

Which has an extra { } around F":{"element":4}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.