@@ -1103,37 +1103,142 @@ public void copyCurrentStructure(JsonParser p) throws IOException
1103
1103
throw new IllegalStateException ("No token available from argument `JsonParser`" );
1104
1104
}
1105
1105
1106
- if (_mayHaveNativeIds ) {
1107
- _checkNativeIds (p );
1108
- }
1109
-
1106
+ // We'll do minor handling here to separate structured, scalar values,
1107
+ // then delegate appropriately
1110
1108
switch (t ) {
1111
1109
case START_ARRAY :
1112
- writeStartArray ();
1113
- while (p .nextToken () != JsonToken .END_ARRAY ) {
1114
- copyCurrentStructure (p );
1110
+ if (_mayHaveNativeIds ) {
1111
+ _checkNativeIds (p );
1115
1112
}
1116
- writeEndArray ();
1113
+ writeStartArray ();
1114
+ _copyContents (p );
1117
1115
break ;
1118
1116
case START_OBJECT :
1119
- writeStartObject ();
1120
- while (p .nextToken () != JsonToken .END_OBJECT ) {
1121
- copyCurrentStructure (p );
1117
+ if (_mayHaveNativeIds ) {
1118
+ _checkNativeIds (p );
1122
1119
}
1123
- writeEndObject ();
1120
+ writeStartObject ();
1121
+ _copyContents (p );
1124
1122
break ;
1125
1123
default : // others are simple:
1126
- copyCurrentEvent ( p );
1124
+ _copyCurrentValue ( p , t );
1127
1125
}
1128
1126
}
1129
1127
1128
+ private final void _copyContents (JsonParser p ) throws IOException
1129
+ {
1130
+ int depth = 1 ;
1131
+ JsonToken t ;
1132
+
1133
+ while ((t = p .nextToken ()) != null ) {
1134
+ switch (t ) {
1135
+ case FIELD_NAME :
1136
+ if (_mayHaveNativeIds ) {
1137
+ _checkNativeIds (p );
1138
+ }
1139
+ writeFieldName (p .getCurrentName ());
1140
+ break ;
1141
+
1142
+ case START_ARRAY :
1143
+ if (_mayHaveNativeIds ) {
1144
+ _checkNativeIds (p );
1145
+ }
1146
+ writeStartArray ();
1147
+ ++depth ;
1148
+ break ;
1149
+
1150
+ case START_OBJECT :
1151
+ if (_mayHaveNativeIds ) {
1152
+ _checkNativeIds (p );
1153
+ }
1154
+ writeStartObject ();
1155
+ ++depth ;
1156
+ break ;
1157
+
1158
+ case END_ARRAY :
1159
+ if (--depth == 0 ) {
1160
+ return ;
1161
+ }
1162
+ writeEndArray ();
1163
+ break ;
1164
+ case END_OBJECT :
1165
+ if (--depth == 0 ) {
1166
+ return ;
1167
+ }
1168
+ writeEndObject ();
1169
+ break ;
1170
+
1171
+ default :
1172
+ _copyCurrentValue (p , t );
1173
+ }
1174
+ }
1175
+ }
1176
+
1177
+ // NOTE: Copied from earlier `copyCurrentEvent()`
1178
+ private void _copyCurrentValue (JsonParser p , JsonToken t ) throws IOException
1179
+ {
1180
+ if (_mayHaveNativeIds ) {
1181
+ _checkNativeIds (p );
1182
+ }
1183
+ switch (t ) {
1184
+ case VALUE_STRING :
1185
+ if (p .hasTextCharacters ()) {
1186
+ writeString (p .getTextCharacters (), p .getTextOffset (), p .getTextLength ());
1187
+ } else {
1188
+ writeString (p .getText ());
1189
+ }
1190
+ break ;
1191
+ case VALUE_NUMBER_INT :
1192
+ switch (p .getNumberType ()) {
1193
+ case INT :
1194
+ writeNumber (p .getIntValue ());
1195
+ break ;
1196
+ case BIG_INTEGER :
1197
+ writeNumber (p .getBigIntegerValue ());
1198
+ break ;
1199
+ default :
1200
+ writeNumber (p .getLongValue ());
1201
+ }
1202
+ break ;
1203
+ case VALUE_NUMBER_FLOAT :
1204
+ if (_forceBigDecimal ) {
1205
+ writeNumber (p .getDecimalValue ());
1206
+ } else {
1207
+ switch (p .getNumberType ()) {
1208
+ case BIG_DECIMAL :
1209
+ writeNumber (p .getDecimalValue ());
1210
+ break ;
1211
+ case FLOAT :
1212
+ writeNumber (p .getFloatValue ());
1213
+ break ;
1214
+ default :
1215
+ writeNumber (p .getDoubleValue ());
1216
+ }
1217
+ }
1218
+ break ;
1219
+ case VALUE_TRUE :
1220
+ writeBoolean (true );
1221
+ break ;
1222
+ case VALUE_FALSE :
1223
+ writeBoolean (false );
1224
+ break ;
1225
+ case VALUE_NULL :
1226
+ writeNull ();
1227
+ break ;
1228
+ case VALUE_EMBEDDED_OBJECT :
1229
+ writeObject (p .getEmbeddedObject ());
1230
+ break ;
1231
+ default :
1232
+ throw new RuntimeException ("Internal error: should never end up through this code path" );
1233
+ }
1234
+ }
1130
1235
1131
- private final void _checkNativeIds (JsonParser jp ) throws IOException
1236
+ private final void _checkNativeIds (JsonParser p ) throws IOException
1132
1237
{
1133
- if ((_typeId = jp .getTypeId ()) != null ) {
1238
+ if ((_typeId = p .getTypeId ()) != null ) {
1134
1239
_hasNativeId = true ;
1135
1240
}
1136
- if ((_objectId = jp .getObjectId ()) != null ) {
1241
+ if ((_objectId = p .getObjectId ()) != null ) {
1137
1242
_hasNativeId = true ;
1138
1243
}
1139
1244
}
0 commit comments