Closed ghost closed 1 year ago
It looks like here it does not use camelCase variable to set key
.
if (nometa) {
if (obj.toJSON) {
raw = obj.toJSON();
} else {
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
raw[key] = Newtonsoft.Json.JsonConvert.SerializeObject(obj[key], formatting, settings, true);
}
}
}
}
Using raw[key.charAt(0).toLowerCase() + key.substr(1)]
for tests generates JSON with camelCase property name.
Strange thing that it works in Bridge. I have tested it and it says: nometa - false.
So in H5 - nometa is true, in Bridge is is false. Obviously above source code does not validate camelCase. So it has bug.
But it is not clear anything yet about H5.getMetadata(type)
.
In H5 t.$getMetadata
is undefined because it is Object, but in Bridge it is "$$fullname": "$AnonymousType$4".
If H5 does not emit anonymous types metadata and type is always object then possible fix probably should look like this:
if (obj.toJSON) {
raw = obj.toJSON();
} else {
var camelCase = settings && H5.is(settings.ContractResolver, Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver);
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
var name = camelCase ? key.charAt(0).toLowerCase() + key.substr(1) : key;
raw[name] = Newtonsoft.Json.JsonConvert.SerializeObject(obj[key], formatting, settings, true);
}
}
}
In H5
t.$getMetadata
is undefined because it is Object, but in Bridge it is "$$fullname": "$AnonymousType$4".
I think this one is related to default behaviour set to [Rules(AnonymousType = AnonymousTypeRule.Plain)] which is not so in Bridge.
@hardhub changing the rule to the Bridge default fixed the issue for you?
@hardhub changing the rule to the Bridge default fixed the issue for you?
It is workaround to emulate Bridge behaviour. But in general it should have the fix:
I have attached full version from my fork: JsonConvert.zip
Thanks @hardhub, merged the change back to the json package now.
Bridge applies camelcase but not H5.
I do not know the reason yet. So just created it here to track the problem.