@@ -314,12 +314,18 @@ function additionalProperty (schema, externalSchema, fullSchema) {
314
314
} else if ( type === 'integer' ) {
315
315
code += `
316
316
${ addComma }
317
- json += $asString(keys[i]) + ':' + $asInteger(obj[keys[i]])
317
+ var t = Number(obj[keys[i]])
318
+ if (isLong && isLong(obj[keys[i]]) || !isNaN(t)) {
319
+ json += $asString(keys[i]) + ':' + $asInteger(obj[keys[i]])
320
+ }
318
321
`
319
322
} else if ( type === 'number' ) {
320
323
code += `
321
- ${ addComma }
322
- json += $asString(keys[i]) + ':' + $asNumber(obj[keys[i]])
324
+ var t = Number(obj[keys[i]])
325
+ if (!isNaN(t)) {
326
+ ${ addComma }
327
+ json += $asString(keys[i]) + ':' + t
328
+ }
323
329
`
324
330
} else if ( type === 'boolean' ) {
325
331
code += `
@@ -364,22 +370,50 @@ function refFinder (ref, schema, externalSchema) {
364
370
365
371
function buildCode ( schema , code , laterCode , name , externalSchema , fullSchema ) {
366
372
Object . keys ( schema . properties || { } ) . forEach ( ( key , i , a ) => {
367
- // Using obj['key'] !== undefined instead of obj.hasOwnProperty(prop) for perf reasons,
368
- // see https://github.com/mcollina/fast-json-stringify/pull/3 for discussion.
369
- code += `
370
- if (obj['${ key } '] !== undefined) {
371
- ${ addComma }
372
- json += '${ $asString ( key ) } :'
373
- `
374
-
375
373
if ( schema . properties [ key ] [ '$ref' ] ) {
376
374
schema . properties [ key ] = refFinder ( schema . properties [ key ] [ '$ref' ] , fullSchema , externalSchema )
377
375
}
378
376
379
- var result = nested ( laterCode , name , key , schema . properties [ key ] , externalSchema , fullSchema )
377
+ // Using obj['key'] !== undefined instead of obj.hasOwnProperty(prop) for perf reasons,
378
+ // see https://github.com/mcollina/fast-json-stringify/pull/3 for discussion.
379
+
380
+ var type = schema . properties [ key ] . type
381
+ if ( type === 'number' ) {
382
+ code += `
383
+ var t = Number(obj['${ key } '])
384
+ if (!isNaN(t)) {
385
+ ${ addComma }
386
+ json += '${ $asString ( key ) } :' + t
387
+ `
388
+ } else if ( type === 'integer' ) {
389
+ code += `
390
+ var rendered = false
391
+ if (isLong && isLong(obj['${ key } '])) {
392
+ ${ addComma }
393
+ json += '${ $asString ( key ) } :' + obj['${ key } '].toString()
394
+ rendered = true
395
+ } else {
396
+ var t = Number(obj['${ key } '])
397
+ if (!isNaN(t)) {
398
+ ${ addComma }
399
+ json += '${ $asString ( key ) } :' + t
400
+ rendered = true
401
+ }
402
+ }
403
+
404
+ if (rendered) {
405
+ `
406
+ } else {
407
+ code += `
408
+ if (obj['${ key } '] !== undefined) {
409
+ ${ addComma }
410
+ json += '${ $asString ( key ) } :'
411
+ `
380
412
381
- code += result . code
382
- laterCode = result . laterCode
413
+ var result = nested ( laterCode , name , key , schema . properties [ key ] , externalSchema , fullSchema )
414
+ code += result . code
415
+ laterCode = result . laterCode
416
+ }
383
417
384
418
if ( schema . required && schema . required . indexOf ( key ) !== - 1 ) {
385
419
code += `
0 commit comments