Skip to content

Commit b8edc1e

Browse files
authored
Merge branch 'main' into 1.5.0
2 parents d49bb46 + bc40a8e commit b8edc1e

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

examples/deserializeYml/deserializeYml.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#include <ArduinoJson.h>
44
#include <YAMLDuino.h>
55

6+
#if ARDUINOJSON_VERSION_MAJOR<7
7+
#error "ArduinoJSON version is deprecated, please upgrade to 7.x"
8+
#endif
9+
610
const char* yaml_sample_str = R"_YAML_STRING_(
711
first: true
812
blah:

examples/test/platformio.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ src_dir = src
66

77
[env]
88
framework = arduino
9+
platform = espressif32
910
lib_deps =
1011
bblanchon/ArduinoJson @ ^7
11-
; tobozo/YAMLDuino @ ^1.5
12+
; tobozo/YAMLDuino @ ^1.5
1213
YAMLDuino
1314
lib_ldf_mode = deep
1415

examples/test/src/test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11

22
#include <ArduinoJson.h>
33

4+
// very dirty but necessary for the CI test
5+
// don't do that in your project!!
6+
#if ARDUINOJSON_VERSION_MAJOR<7
7+
#define ARDUINOJSONDOC DynamicJsonDocument json_doc(2048)
8+
#else
9+
#define ARDUINOJSONDOC JsonDocument json_doc
10+
#endif
11+
412
//#define YAML_DISABLE_CJSON // not needed here
513
//#define YAML_DISABLE_ARDUINOJSON // not needed here
614

@@ -55,6 +63,7 @@ fourth: false
5563
unquoted_hex: 0x1234
5664
double_quoted_hex: "0x1234"
5765
single_quoted_hex: '0x1234'
66+
5867
inline_json_for_the_haters: { "hello":"json", "nested":[3,2,"1","moon"] }
5968
whatever:
6069
nope: ["n","o","p","e"]

src/ArduinoYaml.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,25 +1064,34 @@ namespace YAML
10641064
char* end;
10651065
scalar = SCALAR_s(yamlNode);
10661066
number = strtod(scalar, &end);
1067+
bool is_double = false;
10671068
bool is_bool = false;
10681069
bool bool_value = false;
10691070
bool is_string = quoted_implicit || (end == scalar || *end);
10701071
if( is_string && yaml_node_is_bool( yamlNode, &bool_value ) ) {
10711072
is_bool = true;
10721073
}
1074+
if( SCALAR_Quoted(yamlNode) ) {
1075+
is_string = true;
1076+
}
1077+
if( !is_bool && !is_string ) {
1078+
is_double = String(scalar).indexOf(".") > 0;
1079+
}
10731080
switch( nt ) {
10741081
case YAMLNode::Type::Sequence:
10751082
{
10761083
JsonArray array = jsonNode[nodename];
10771084
if(is_bool) array.add( bool_value );
10781085
else if(is_string) array.add( scalar );
1079-
else array.add( number );
1086+
else if(is_double) array.add( number );
1087+
else array.add( (int64_t)number );
10801088
}
10811089
break;
10821090
case YAMLNode::Type::Map:
10831091
if(is_bool) jsonNode[nodename] = bool_value;
10841092
else if(is_string) jsonNode[nodename] = scalar;
1085-
else jsonNode[nodename] = number;
1093+
else if(is_double) jsonNode[nodename] = number;
1094+
else jsonNode[nodename] = (int64_t)number;
10861095
break;
10871096
default: YAML_LOG_e("Error invalid nesting type"); break;
10881097
}
@@ -1110,8 +1119,6 @@ namespace YAML
11101119
deserializeYml_JsonObject( document, itemNode, jsonNode, YAMLNode::Type::Sequence, _nodeItemName.c_str(), depth+1 );
11111120
}
11121121
}
1113-
1114-
11151122
}
11161123
break;
11171124
case YAML_MAPPING_NODE:

src/ArduinoYaml.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ namespace YAML
128128
// shorthand to libyaml scalar values
129129
#define SCALAR_c(x) (const char*)x->data.scalar.value
130130
#define SCALAR_s(x) (char*)x->data.scalar.value
131+
#define SCALAR_Quoted(n) n->data.scalar.style == YAML_SINGLE_QUOTED_SCALAR_STYLE || n->data.scalar.style == YAML_DOUBLE_QUOTED_SCALAR_STYLE
131132

132133
void setYAMLIndent( int spaces_per_indent=2 ); // min=2, max=16
133134
void setJSONIndent( const char* spaces_or_tabs=JSON_SCALAR_TAB, int folding_depth=JSON_FOLDING_DEPTH );

0 commit comments

Comments
 (0)