Weird behaviour on toJSON method
See original GitHub issueWhen you fill a child element with an invalid value toJSON method acts in a weird way. The parent toJSON
returns the old child element and the toJSON
of the child element returns the child element in the invalid state.
For example, given the schema:
class MyEntity extends Speck {
static SCHEMA = {
field: PropTypes.string,
anotherField: PropTypes.string
}
}
class FatherEntity extends Speck {
static SCHEMA = {
child: PropTypes.instanceOf(MyEntity)
}
}
And the variables setup:
const a = new FatherEntity({ child: { field: 'value' } })
a.child = { field: 'invalid entity', anotherField: 'yet a invalid entity' }
The toJSON
method have this behaviour:
//prints { child: { field: 'value' } }
console.log(a.toJSON())
//prints { field: 'invalid entity', anotherField: 'yet a invalid entity' }
console.log(a.child.toJSON())
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Date object to JSON weird behaviour - Stack Overflow
So I suppose every 'toJSON' method uses toISOString method within.. :) So problem is solved - probably its default behaviour that 'jsonizing' ...
Read more >JSON and the stringification oddities in JavaScript - Zhenghao
Surprising and inconsistent behaviour of JSON.stringify# ... In JavaScript, the way to convert a value to a JSON string is via JSON.stringify ....
Read more >Weird behavior during parsing Json - Microsoft Q&A
Weird behavior during parsing Json. I'm parsing this JSON ... Public Shared Function FromJson(ByVal json As String) As Openorders ...
Read more >Strange & annoying JSON behavior in ExtendScript.
The problem is, in the following JSX code I get a result where all empty objects and empty arrays are split into having...
Read more >Weird JSON object behavior? - ShapeDiver - McNeel Forum
Hey Devs,. Just a quick one to point out that I personally think that the ShapediverJSONConstruct object does not act the way i...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
try with :
I can’t simulate this error anymore. For now I think that is better to close this issue.