Comments (2)
Basically, migrations are not getting called for some serialized objects that happen to be referenced by "$ref" later on. I attempted to fix MigrationConverter.ReadJson to check for ref, and to return the referenced object:
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var data = JToken.Load(reader);
//don't try and repeat migration for objects serialized as refs to previous
if (data["$ref"] != null)
{
return serializer.ReferenceResolver.ResolveReference(serializer, (string)data["$ref"]);
}
var migratedData = DataMigrator.TryMigrate(data, objectType, serializer);
...
This fix does work to prevent the migration methods from getting called on encountered "$ref" JTokens. However, the migrations DO NOT get called on the initial deserialization of those objects.
Just to confirm that there isn't anything wonky with my test data or a fundamental misunderstanding of anything, I implemented a JsonConverter<> to perform the same migrations as I was attempting to do with this lib. For the very same dataset, all JTokens for my class are migrated correctly in order. So there is something about your particular implementation that breaks when using references, besides not detecting/resolving them in ReadJson
.
Update:
I punted and wrote my own migration code. I'm somewhat confident that this library could be updated to suit my purposes but I just don't have time to work on a PR at the moment. I may revisit, or in case someone else digs into this, the following SO links may prove helpful:
Trying to implement a JSON version migrator by implementing JsonConverter<T>
Generic method of modifying JSON before being returned to client
JSON.Net throws StackOverflowException when using [JsonConvert()]
from migrations.json.net.
@Awsmolak hey mate!
I rewrote this plugin and made it from 5 to 10 times faster
Link to plugin: https://github.com/vangogih/FastMigrations.Json.Net
And also added the feature with PreserveReferencesHandling
support.
Link to test case
It has been a while since your comment but I hope you will find the time to check this test case to be sure that I have wrote it correctly ;)
Looking forward to getting feedback from you!
from migrations.json.net.
Related Issues (18)
- Support VS2015 and .Net 4.6 on build server HOT 1
- Verify migration HOT 1
- Support nested migratable types HOT 1
- NuGet dependencies don't work
- Add more analyzers/code fixes HOT 1
- Check if test project compiles HOT 1
- Populating object that has read-only getter doesn't work
- Migration method verification is broken HOT 1
- Error when deserializing with PreserveReferencesHandling.Objects
- Weingartner.Json.Migration.Roslyn.MigrationHashAnalyzer cannot be created HOT 3
- NullReferenceException MigrationHashHelper HOT 2
- Documentation HOT 3
- Custom migrator
- Version field doesn't work with inheritance HOT 2
- Doesn't work with IL2Cpp HOT 4
- MigratableAttribute / [Migratable("xxxx")] HOT 1
- This plugin is outdated and unsupported
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from migrations.json.net.