GithubHelp home page GithubHelp logo

ngrodzitski / json_dto Goto Github PK

View Code? Open in Web Editor NEW
11.0 11.0 4.0 55 KB

A small header-only helper for converting data between json representation and c++ structs.

License: BSD 3-Clause "New" or "Revised" License

Ruby 5.50% C++ 94.50%
cplusplus json

json_dto's People

Contributors

ngrodzitski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

json_dto's Issues

Got 'no matching function for call' error

When I try to build the project with json_dto, I get the following error:

json_dto/pub.hpp:210:33: error: no matching function for call to 'rapidjson::GenericValue<rapidjson::UTF8<> >::SetString(const string&, rapidjson::MemoryPoolAllocator<>&)'
  object.SetString( s, allocator );

foreach properties

Hello! I want to perform an operation for each property of my object. How can I do this better? For example :

struct RegisterState
{
	string	deviceName;
	string	registerName;
	
	template < typename Json_Io >
	void json_io(Json_Io & io)
	{
		io
			& json_dto::mandatory(
				"deviceName",
				deviceName)
			& json_dto::mandatory(
				"registerName",
				registerName)
			;
	}
}; 

.................

RegisterState regState;
for (auto property : regState)
{
    cout << property.name << " = " << property.value;
}

Invalid deserialization

Hello

I have the following code:

class A {
public:
    float f;

    A() {}

    A(float f) :
            f(f) {}
};

namespace json_dto {
    template<typename JSON_IO>
    void json_io(JSON_IO& io, A a) {
        io
        & json::mandatory("f", a.f);
    }
}

After

auto v1 = A(10.8);
auto v = json_dto::to_json(v1);
std::cout << v << std::endl;
auto v2 = json_dto::from_json<A>(v);
std::cout << json_dto::to_json(v2) << std::endl;

I get
{"f":10.800000190734864}
{"f":1041031353073664.0}

Could you please help, where is my mistake?

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.