My complex type wouldn't pass from Show to Init method even with configured MvxJsonNavigationSerializer as specified here Custom types in Navigation parameters in v3
public class A
{
public string String1 {get;set;}
public string String2 {get;set;}
public B ComplexObject1 {get;set;}
}
public class B
{
public double Double1 {get;set;}
public double Double2 {get;set;}
}
When I pass instance of object A to ShowViewModel method I receive this object with String1 & String2 deserialized correctly but CopmlexObject1 is null.
How to deal with complex object MvvmCross serialization?
A small addition to Stuart's answer to add type safety:
ShowViewModel
method now takes the same parameter type that theRealInit
method instead of anobject
type. Also,BaseViewModel<TInit>
inherits fromBaseViewModel
so their instances can also call the newShowViewModel
method.The only drawback is that you have to explicitly specify the parameter type in the call like this:
I believe there may be some gremlins in that previous answer - will log as an issue :/
There are other possible routes to achieve this type of complex serializable object navigation still using Json and overriding parts of the framework, but actually I think that it might be better to just use your own BaseViewModel's to do serialization and deserialization - e.g. use serialization code like:
with deserialization like:
then a viewModel like this:
can navigate to something like: