@@ -75,36 +75,33 @@ public static ExprValue castJson(ExprValue json) {
75
75
}
76
76
77
77
private static ExprValue processJsonNode (JsonNode jsonNode ) {
78
- if (jsonNode .isFloatingPointNumber ()) {
79
- return new ExprDoubleValue (jsonNode .asDouble ());
78
+ switch (jsonNode .getNodeType ()) {
79
+ case ARRAY :
80
+ List <ExprValue > elements = new LinkedList <>();
81
+ for (var iter = jsonNode .iterator (); iter .hasNext (); ) {
82
+ jsonNode = iter .next ();
83
+ elements .add (processJsonNode (jsonNode ));
84
+ }
85
+ return new ExprCollectionValue (elements );
86
+ case OBJECT :
87
+ Map <String , ExprValue > values = new LinkedHashMap <>();
88
+ for (var iter = jsonNode .fields (); iter .hasNext (); ) {
89
+ Map .Entry <String , JsonNode > entry = iter .next ();
90
+ values .put (entry .getKey (), processJsonNode (entry .getValue ()));
91
+ }
92
+ return ExprTupleValue .fromExprValueMap (values );
93
+ case STRING :
94
+ return new ExprStringValue (jsonNode .asText ());
95
+ case NUMBER :
96
+ if (jsonNode .isFloatingPointNumber ()) {
97
+ return new ExprDoubleValue (jsonNode .asDouble ());
98
+ }
99
+ return new ExprIntegerValue (jsonNode .asLong ());
100
+ case BOOLEAN :
101
+ return jsonNode .asBoolean () ? LITERAL_TRUE : LITERAL_FALSE ;
102
+ default :
103
+ // in all other cases, return null
104
+ return LITERAL_NULL ;
80
105
}
81
- if (jsonNode .isIntegralNumber ()) {
82
- return new ExprIntegerValue (jsonNode .asLong ());
83
- }
84
- if (jsonNode .isBoolean ()) {
85
- return jsonNode .asBoolean () ? LITERAL_TRUE : LITERAL_FALSE ;
86
- }
87
- if (jsonNode .isTextual ()) {
88
- return new ExprStringValue (jsonNode .asText ());
89
- }
90
- if (jsonNode .isArray ()) {
91
- List <ExprValue > elements = new LinkedList <>();
92
- for (var iter = jsonNode .iterator (); iter .hasNext (); ) {
93
- jsonNode = iter .next ();
94
- elements .add (processJsonNode (jsonNode ));
95
- }
96
- return new ExprCollectionValue (elements );
97
- }
98
- if (jsonNode .isObject ()) {
99
- Map <String , ExprValue > values = new LinkedHashMap <>();
100
- for (var iter = jsonNode .fields (); iter .hasNext (); ) {
101
- Map .Entry <String , JsonNode > entry = iter .next ();
102
- values .put (entry .getKey (), processJsonNode (entry .getValue ()));
103
- }
104
- return ExprTupleValue .fromExprValueMap (values );
105
- }
106
-
107
- // in all other cases, return null
108
- return LITERAL_NULL ;
109
106
}
110
107
}
0 commit comments