Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.12.4 version Json set enum value failed #4341

Closed
xzzh999 opened this issue Dec 13, 2023 · 0 comments
Closed

1.12.4 version Json set enum value failed #4341

xzzh999 opened this issue Dec 13, 2023 · 0 comments

Comments

@xzzh999
Copy link

xzzh999 commented Dec 13, 2023

Describe the bug

Poco::JSON::Object::Ptr obj = new Poco::JSON::Object();

// set some enum value
obj->set("taskType", SOME_ENUM_VALUE);

Poco::Dynamic::Var var(obj);
std::string result = var.convert<std::string>();

got exception:

poco got exception: Can not convert to std::string

if changed to this:

obj->set("taskType", int(SOME_ENUM_VALUE));

it works fine.

To Reproduce
always failed

Expected behavior
json convert ok

Logs
poco got exception: Can not convert to std::string

Please add relevant environment information:

  • Win 10 x64 19044.3693
  • 1.12.4

Additional context
none

@xzzh999 xzzh999 added the bug label Dec 13, 2023
@xzzh999 xzzh999 changed the title Poco 1.12.4 Json set enum value failed 1.12.4 version Json set enum value failed Dec 13, 2023
bas524 added a commit to bas524/poco that referenced this issue Dec 21, 2023
add testEnum
if you set enum as json value then it will be cast to int
@aleks-f aleks-f added feature and removed bug labels Jan 4, 2024
aleks-f pushed a commit that referenced this issue Feb 1, 2024
* fix issue #4341
add testEnum
if you set enum as json value then it will be cast to int

* add behavour for enum into VarHolderImpl
add tests for enum classes with differnent underline integral types

* replace static_cast with convertTo* methods, they can chaeck types and
limits

* fix missing types for convert methods

* fix code style
add testEnumType to the VarTest.cpp, extract() works
matejk pushed a commit that referenced this issue Mar 26, 2024
* fix issue #4341
add testEnum
if you set enum as json value then it will be cast to int

* add behavour for enum into VarHolderImpl
add tests for enum classes with differnent underline integral types

* replace static_cast with convertTo* methods, they can chaeck types and
limits

* fix missing types for convert methods

* fix code style
add testEnumType to the VarTest.cpp, extract() works
@aleks-f aleks-f added this to 1.14 Jul 29, 2024
@aleks-f aleks-f added this to the Release 1.14.0 milestone Jul 29, 2024
aleks-f added a commit that referenced this issue Jul 29, 2024
* Allow set enum as json value (#4363)

* fix issue #4341
add testEnum
if you set enum as json value then it will be cast to int

* add behavour for enum into VarHolderImpl
add tests for enum classes with differnent underline integral types

* replace static_cast with convertTo* methods, they can chaeck types and
limits

* fix missing types for convert methods

* fix code style
add testEnumType to the VarTest.cpp, extract() works

* enh(VarHolder): replace ::value and ::type with shortcuts

---------

Co-authored-by: Alexander B <ale.bychuk@gmail.com>
@matejk matejk added the fixed label Sep 12, 2024
@matejk matejk moved this to Done in 1.14 Sep 12, 2024
@matejk matejk closed this as completed Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

3 participants