You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(Note: size is actually longer, but for simplicity I chose 6)
Serialization and deserialization works fine. Hash gets converted to an array of 6 values in the json representation.
However, I would prefer to have a compact representation as a string, showing hex values. So I started custom implementations for de-/serialization (inside the namespace tools as mentioned in the docs):
When I want to de-/serialize my custom implementations are only used if I add an explicit call to the functions including the namespace.
In all other cases it seems the internal implementation for arrays is called:
******** Convert from Hash to json **********
Convert assignment [171,35,116,0,18,37]
Convert call to_json [171,35,116,0,18,37]
Convert call tools::to_json "ab2374001225"
******** Convert from json to Hash **********
Exception during `hash = json;`: [json.exception.type_error.302] type must be array, but is string
Exception during `from_json( json, hash );`: [json.exception.type_error.302] type must be array, but is string
Convert from assignment 000000000000
Convert call from_json 000000000000
Convert call tools::from_json ab2374001225
So either assignment as well as direct call to to_/from_json use the internal "std::array" version.
Yielding the json array representation or throwing an exception when a string is fed to the function.
Only by calling explicitly tools::to_json and tools::from_json will yield the intended result.
Question
Is there anything I'm missing out, or do I need to call the conversion explicitly in my case?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Description
I encountered a problem, where I'm not sure whether I'm doing something wrong.
I want to create a type for a hash value. For this I use the std::array:
(Note: size is actually longer, but for simplicity I chose 6)
Serialization and deserialization works fine. Hash gets converted to an array of 6 values in the json representation.
However, I would prefer to have a compact representation as a string, showing hex values. So I started custom implementations for de-/serialization (inside the namespace
tools
as mentioned in the docs):When I want to de-/serialize my custom implementations are only used if I add an explicit call to the functions including the namespace.
In all other cases it seems the internal implementation for arrays is called:
Example
I've created an example to visualize what I'm doing:
When I run this example I get this output:
So either assignment as well as direct call to to_/from_json use the internal "std::array" version.
Yielding the json array representation or throwing an exception when a string is fed to the function.
Only by calling explicitly
tools::to_json
andtools::from_json
will yield the intended result.Question
Is there anything I'm missing out, or do I need to call the conversion explicitly in my case?
Beta Was this translation helpful? Give feedback.
All reactions